Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to Jest Expect #6

Merged
merged 18 commits into from
Oct 6, 2017
Merged

Move to Jest Expect #6

merged 18 commits into from
Oct 6, 2017

Conversation

frytyler
Copy link
Contributor

@frytyler frytyler commented Oct 4, 2017

This PR removes chai package which was primarily using the assert style tests in favour of using standard jest except assertions.

All tests are passing as they were before, in the process of converting I refactored the tests to read a bit better. There were a few tests in PromiseMiddleware.test.js that were throwing unhandled promise rejection warnings, these have all been resolved through the reorganization of the tests.

I opted to use sinon.spy's to assist in the readability of the tests.

This will complete #3

Closes #3

@frytyler
Copy link
Contributor Author

frytyler commented Oct 5, 2017

@tizmagik let me know if you need any changes on this

Copy link
Contributor

@tizmagik tizmagik left a comment

Choose a reason for hiding this comment

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

This is awesome, thank you! Especially for fixing that unhandled promise thing, that's great!

Do you think we can drop sinon as well? I added a comment about Jest's built in "spy"-ability. Let me know what you think. Thanks!


actionHandler(actionObj);

expect(actionSpy.calledOnce).toBeTruthy();
expect(actionSpy.firstCall.args[0]).toEqual(actionObj);
Copy link
Contributor

@tizmagik tizmagik Oct 5, 2017

Choose a reason for hiding this comment

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

I think you can actually drop sinon and get away with using Jest's built-in spy, jest.fn() here and elsewhere. For example:

const actionSpy = jest.fn();
const actionHandler = nextHandler(actionSpy);

actionHandler(actionObj);

expect(actionSpy).toHaveBeenCalledTimes(1);
expect(actionSpy).toHaveBeenCalledWith(actionObj);

@frytyler
Copy link
Contributor Author

frytyler commented Oct 5, 2017

@tizmagik Jest mocks for the win. They actually reduced a few areas down a bit which was nice. I also fixed the skipped test in registerAsyncActions. I split it into 3 tests and asserted in the catch, Maybe have a quick look to make sure they are doing what you want as I didn't have thing to compare to from before.

@frytyler frytyler mentioned this pull request Oct 5, 2017
Copy link
Contributor

@tizmagik tizmagik left a comment

Choose a reason for hiding this comment

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

Awesome work, thank you!

@tizmagik tizmagik merged commit 12b86d7 into nytimes:master Oct 6, 2017
tizmagik pushed a commit that referenced this pull request Oct 6, 2017
* Initial jest conversion

* Remove macho setup and remove jsdom package.

* PromiseMiddleware test refactor.

* Refactor ReduxTaxi tests to jest expect

* Refactor ReduxTaxiMiddleware test to jest expect

* Refactor ReduxTaxiProvider to jest expect

* Refactor RegisterAsyncActions test to jest expect

* Remove chai package

* Remove trailing commas

* Add Prettier

* Add Prettier

* Update list-staged file catch

* Run Prettier on all JS files

* Remove sinon in favor for jest mocks.

* removing prettier deps from this PR.

* packages.

* Prettier pre-hook and reformat current files.

* 2 spaces in editorconfig.

* Create .travis.yml (#11)

* Create .travis.yml

* Update .travis.yml

* Update .travis.yml

* Update .travis.yml

* Update .travis.yml

* Move to Jest Expect (#6)

* Initial jest conversion

* Remove macho setup and remove jsdom package.

* PromiseMiddleware test refactor.

* Refactor ReduxTaxi tests to jest expect

* Refactor ReduxTaxiMiddleware test to jest expect

* Refactor ReduxTaxiProvider to jest expect

* Refactor RegisterAsyncActions test to jest expect

* Remove chai package

* Remove trailing commas

* Add Prettier

* Add Prettier

* Update list-staged file catch

* Run Prettier on all JS files

* Remove sinon in favor for jest mocks.

* removing prettier deps from this PR.

* remove trailing comma

* Initial jest conversion

* Remove macho setup and remove jsdom package.

* Remove chai package

* Remove trailing commas

* Add Prettier

* Add Prettier

* Update list-staged file catch

* Run Prettier on all JS files

* Remove sinon in favor for jest mocks.

* removing prettier deps from this PR.

* packages.

* Prettier pre-hook and reformat current files.

* 2 spaces in editorconfig.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor tests to Jest
2 participants