Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Add tests for utils #27

Merged
merged 2 commits into from
Feb 8, 2018
Merged

Add tests for utils #27

merged 2 commits into from
Feb 8, 2018

Conversation

jimbo
Copy link
Contributor

@jimbo jimbo commented Feb 7, 2018

No description provided.

return { foo: 'foo', default: 'bar' };
}

describe('extract', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop the describe so we're matching our tests across our other repos?

test('extract retrieves a named export');
test('extract retrieves the default export');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I think when this file has a few more functions the test output will be unreadable if not grouped by describe, but then, they're just tests.

*
* @param {object} obj - A module's namespace object
* @param {string} name - The key to look up
* @param {string} name - The binding to retrieve
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're listing the params, would make sense to list the return (then VSCode/Webstorm will give proper hinting).

@returns {Promise<*>}

image

@@ -0,0 +1,12 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of having 2 separate Babel configuration files. We should choose 1 and confine all babel-related config to it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to keep the JS version, jestjs/jest#1468 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm also not a fan of it. I considered moving everything to .babelrc, but it's pretty verbose that way. Could still be better than hacking jest, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever route you choose is just temporary until Babel 7, and then we have first-class support for .babelrc.js

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep 2 files instead of using a hack. More maintenance, but the maintenance burden is obvious.

Copy link
Contributor Author

@jimbo jimbo Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my instinct here as well, @zetlen. And @DrewML we should consolidate both files into .babelrc.js as soon as we're on 7.0 then.

test('yields undefined', () => {
const gen = fixedObserver(2);

expect.assertions(3);
Copy link
Contributor

@DrewML DrewML Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason you're using an assertion counter? Typically only needed for async code where the "bad" path would exit without throwing.

Example:

test('Should throw', async () => {
   try {
      await foo();
      // if foo does not reject, test passes (incorrectly)
   } catch(err) {
       expect(err).toBeTruthy();
   }
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, no reason. Saw it in other tests @zetlen wrote and imitated it without opinion.

Copy link
Contributor

@DrewML DrewML Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a huge deal here (small tests), but I have a strong pref in general to not use it when it isn't necessary. Last employer started having 50+ line tests, and any test you edited always failed because you'd forget to change the assertion counter - became a PITA.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I only add it when during my development of the test, it somehow passed without running my async assertions. I probably shouldn't do it--I should add expect.hasAssertions() for asserting any amount of later async assertions, which needs less upkeep.

Copy link
Contributor

@zetlen zetlen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nothing here is blocking--just comments!

@@ -0,0 +1,12 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep 2 files instead of using a hack. More maintenance, but the maintenance burden is obvious.

test('throws if the module fails to resolve', async () => {
const error = new Error('Invalid namespace object provided.');

await expect(extract(null)).rejects.toEqual(error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing rejections has been really annoying in Jest, but since this was fixed in 22, you can write a nicer test here:

test('throws if the module fails to resolve', () =>
    expect(extract(null)).rejects.toEqual(error)
);

(You don't have to async/await if you can return the Promise directly out of the test.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can remove the superfluous await.

@DrewML DrewML merged commit d34a728 into master Feb 8, 2018
@DrewML DrewML deleted the jimbo/gallery-tests branch February 8, 2018 17:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants