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

Add: 'expect.js' to Jest expect codeshift #67

Merged
merged 1 commit into from
Aug 20, 2017

Conversation

jordalgo
Copy link

@jordalgo jordalgo force-pushed the expectJsTransformer branch from 6d28231 to af0c932 Compare August 18, 2017 01:35
Copy link
Owner

@skovhus skovhus left a comment

Choose a reason for hiding this comment

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

Thank you so much for this. Really nice work!

I have a few comments that I hope you have time to address. : )

`
const test = require("testlib");
test(t => {
expect(stuff).toExist();
Copy link
Owner

Choose a reason for hiding this comment

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

It seems expect.js doesn't have toExist, so for this test to be more valuable it would be nice to change this to to.be.ok(); (that expect.js) supports

Copy link
Author

Choose a reason for hiding this comment

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

No problem, will add.

test(() => {
expect(stuff).toBeTruthy();
expect(stuff).toBeFalsy();
expect(stuff).toBeFalsy();
Copy link
Owner

Choose a reason for hiding this comment

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

empty: asserts that an array is empty or not

So expect(stuff).to.be.empty(); should be translated to expect(stuff).toHaveLength(0).

Copy link
Author

Choose a reason for hiding this comment

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

👍

`,
`
test(() => {
fail('message');
Copy link
Owner

Choose a reason for hiding this comment

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

This doesn't look like valid Jest code. I think this should be converted to:

test(done => {
  done.fail('message');
})

See the ava transformer that does something similar

Copy link
Author

Choose a reason for hiding this comment

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

Even though it's not in the docs, I believe this is a Jasmine convention for explicit sync test failures which maps to expect.js expect().fail('message'); Is there a reason the done is needed?

Copy link
Owner

Choose a reason for hiding this comment

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

Jest is using their own version of Jasmine now, so please investigate what works.

As my code example shows done is passed in as a parameter to the test.

Copy link
Author

Choose a reason for hiding this comment

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

I tested and fail does work as expected and I think it's supported here but perhaps the best thing to do is just throw a new Error instead of using this.

Copy link
Owner

Choose a reason for hiding this comment

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

I think fail is fine then.

Copy link
Author

Choose a reason for hiding this comment

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

I might actually prefer throw Error(msg) since fail isn't in the Jest docs -- do you have a preference?


No support yet for the follow expect.js conventions:

expect({ a: 'b', c: 'd' }).to.only.have.keys(['a', 'c']);
Copy link
Owner

Choose a reason for hiding this comment

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

Please log a warning if this is used. See some of the other transformers where we also log an error if you are using unsupported features. And add a test. : )

And if you want to implement it, the chai-should does something similar.

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good. I'll check that out.

testChanged(
'standaloneMode: keeps expect import',
`
import exp from 'expect';
Copy link
Owner

Choose a reason for hiding this comment

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

I guess this should be import exp from 'expect.js'; that is converted to import expect from 'expect';

@jordalgo
Copy link
Author

@skovhus Thanks so much for the fast and great review! Will get those changes in shortly.

@jordalgo jordalgo force-pushed the expectJsTransformer branch from af0c932 to ec69a2f Compare August 18, 2017 13:30
@jordalgo
Copy link
Author

@skovhus - I believe I addressed all your comments in the latest update.

@jordalgo
Copy link
Author

Actually, hold off on merging -- I need to fix one more thing.

@jordalgo jordalgo force-pushed the expectJsTransformer branch from ec69a2f to c78b326 Compare August 18, 2017 16:20
@jordalgo
Copy link
Author

Ok should be good to go now. Added a few more test cases for throwError.

Copy link
Owner

@skovhus skovhus left a comment

Choose a reason for hiding this comment

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

Can I get you to update cli.js and the README? Thanks!

@jordalgo jordalgo force-pushed the expectJsTransformer branch from c78b326 to 861503c Compare August 19, 2017 11:06
@jordalgo
Copy link
Author

@skovhus Done 👍

@skovhus
Copy link
Owner

skovhus commented Aug 19, 2017

Awesome! Small linting (I'll add a pre commit hook one day) issue, else good to go.

@jordalgo jordalgo force-pushed the expectJsTransformer branch from 861503c to e71cd18 Compare August 19, 2017 11:27
@jordalgo
Copy link
Author

Oops. Fixed.

@skovhus skovhus merged commit bbb8337 into skovhus:master Aug 20, 2017
@skovhus
Copy link
Owner

skovhus commented Aug 20, 2017

@jordalgo Thank you for the beautiful contribution!

https://github.com/skovhus/jest-codemods/releases/tag/0.12.0

🎉

@skovhus
Copy link
Owner

skovhus commented Aug 20, 2017

Out of curiosity, did you use this at Spotify? : )

@jordalgo
Copy link
Author

@skovhus Awesome! Thanks for the fast feedback. And yes, this codemod got used a lot this past week at Spotify as we're migrating the unit tests in one of our big repos from Mocha (and expect.js) to Jest -- know any good codemods for sinon to Jest mocks 😜 ?

@skovhus
Copy link
Owner

skovhus commented Aug 25, 2017

@jordalgo thanks! Good luck with the migration. :)

I would really like us to support Sinon. Parts of it should be fairly easy to do. Let me know in #68 if you have any input.

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.

2 participants