-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Use the "expect" npm package #1679
Comments
@mjackson i think the biggest issue will be migrating the issue here is that it depends on some jest global state (like current running test, filename, whether it's running in |
@DmitriiAbramov Help me understand. Right now, |
Coupling this to the global state of a specific runner for snapshots would make this a non-starter. I'm also confused why nothing would be thrown immediately (also seems like that would break usage in other test runners). |
@phated It's my understanding that |
We won't be adding the snapshot matcher to expect from the beginning. For now it will just be |
I don't know how import {createSnapshotState, processSnapshot} from 'jest-snapshot';
const fileName = "/home/whoever/whatever.snap.js";
const snapshotName = "renders correctly 1";
const actual = {/* ... */};
const options = {updateSnapshot: true}; // or false
const snapshotState = createSnapshotState(fileName);
const {pass, expected} = processSnapshot(snapshotState, snapshotName, actual, options); So as long as you can bring your own |
Small update: we just added |
@cpojer woo! That was definitely one of the largest differences. Is there a branch I can try out? Or did you put it in a release already? I'll make some time soon to check out |
Hey @mjackson, we are tracking this internally right now. The JS Tools team is pretty busy until the end of year with our three projects (Yarn, Jest and react-native-packager) so we may not make a ton of progress on this immediately but it's definitely one of our goals to make this work well. I'll share something more soon :) |
@mjackson FWIW after using both the chai style |
I agree, Jeff. I don't like the chai style either. We're moving to the See the difference?
|
I believe there is value in the |
@mjackson yes, I agree that wouldn't be too bad if we are just adding one dot clause. |
Absolutely, it affects the UX. Thanks for chiming in here and caring, Jeff :) FWIW, I think that For plugins, authors only have to write one assertion instead of two. So, e.g. if I want to make a For users, I only have to remember one form of the assertion instead of 2. |
I would also like to add that I use jasmine API sometimes, like spyOn that will be covered with jest once this comes out, but there's one more example where I use jasmine:
Because we are also passing anonymous callback function as 3rd parameter we have to expect it because .toHaveBeenCalledWith function will fail if we try to expect only first 2 arguments without selecting last one. I don't mind using jasmine, just giving an example for you guys to decide if it's worth covering this with jest. |
@vjeux is helping out to make this a reality. Here is what was done so far, among adding a ton of features to
TODO
Assuming we'll figure out these things soon, are you happy to transfer ownership of the project to us? |
I forget if this has been brought up but can this remain es5-compatible? |
(edit): We'll likely support the syntax that is supported in node 4 and up. You can add an additional transformation step for the environment you are using. Also, the current expect library is great and works well. If you've been happy about using it in the past and you don't want to upgrade on existing projects, I think that's fine too. |
It doesn't make much difference, but my vote for |
Awesome, thanks @vjeux! :D
|
Can you provide us with an integration test? How does expect work in the browser? Do you ship a single build file of it or do you let webpack/browserify take care of the bundling? There is nothing that should prevent jest-matchers to work in the browser (assuming cc @zertosh who knows how to create bundles for webpack. Can you help us get a build file of the "jest-matchers" package? |
@mjackson Jest is also running in |
Hey @skovhus, you are a codemod pro. Do you think you could help us out here by taking https://github.com/cpojer/js-codemod/blob/master/transforms/expect.js and putting it into jest-codemods and adding a few of the fixes that @kentor just mentioned? |
@jpojer thanks, would love to add that to Jest Codemods. On vacation this week, but will look into it next week. ; ) |
FYI |
Happy to say that the transformer for this in Jest-Codemods is almost there (see progress in skovhus/jest-codemods#39). Think it will get most projects 95% of the way when transitioning from expect@1 to Jest/Jest-matchers. Trying it out on a few ReactTraining repos, shows that we got some ES2015 in |
@skovhus if it isn't supported right now, we should add that API to |
I think |
PR for it: #4345 |
|
@gaearon Proof of concept of running |
I decided to wrap the Include
See sample JS Bin jsbin/wapokahaxe. @gaearon Heads up! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'd like to donate use of the expect npm package to the Jest project. We're both working on very similar
expect
-style APIs, except you guys are killing it with awesome error messages and I'm not. So I wanna let you run with it :)AFAICT there are only a few places where our APIs differ. Please correct me if I'm wrong. They are:
expect
uses e.g..toNotEqual
instead of.not.toEqual
. TBH I like the.not
notation better. Otherwise you end up creating a negated form of every single assertion. So this is 👍 . I'm fine w breaking backwards compat. Maybe we can provide a codemod for people who want to automate the upgrade process. Should be a simples/toNot/not.to/g
.expect
includes support for mocha's error diffing when usingtoEqual
(see here). I don't expect full mocha support, but I'd like to keep at least this one aspect for people currently usingexpect
with mocha to help make the transition to Jest easier.expect
exposes its basic assert function for those who just need toexpect.assert(something)
. I don't see this in Jest. Would it be easy to expose this?expect
includes anexpect.extend
method for extending the core assertions. We use it e.g. inexpect-element
to generate assertions specific to DOM nodes andexpect-jsx
for JSX. Inexpect
we just add properties toExpectation.prototype
. Does Jest have a method for doing something similar?expect
has aexpect.createSpy
API where you usejest.fn
.expect.createSpy
could just be a simple alias forjest.fn
.expect
has anexpect.spyOn
function. I don't see this in Jest, but it should be pretty easy to keep it. It's just a wrapper forcreateSpy
.expect
have acalls
property that is an array of{ context, arguments }
objects. Jest usesmock.calls
that is an array of arguments. I'm fine with deprecating and using Jest's API here. Just something to note for people upgrading.Overall I think this should be fairly easy from my side. Not sure what this looks like from your side though. Anything I missed?
/cc @cpojer
The text was updated successfully, but these errors were encountered: