-
-
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
[Feature]: Expose equals from expect package. #11867
Comments
So there's no need to import it or have a dependency |
Hmm, I guess this isn't a custom matcher, but used within the mock function itself? That's a bit more tricky. Essentially same as #11816 |
I know it's a hack but could I make a custom matcher and manually trigger it in order to get access to the let equals = () => {}
expect.extend({
__capture_equals__ () {
equals = this.equals
return { pass: true }
}
})
expect().__capture_equals__()
// Now I can use equals
equals(a, b) Update: It seems to kind of work. All jest-when tests except 2 are passing. |
That should work, yeah. I'll try to get a proper fix for this in Jest 28 |
I would like to second the request to expose equals from expect, but for an entirely different reason, that might lead to a slightly different solution. I'm using jest-snapshot outside of jest, as per https://medium.com/blogfoster-engineering/how-to-use-the-power-of-jests-snapshot-testing-without-using-jest-eff3239154e5. The modularity of jest is allowing me to migrate a large mocha-based test suite to using snapshots, with a view to migrating to full jest sometime later. Incremental rewrites = super cool 😎 . However, the method outlined in the blog post (and all of the existing tools I can find around like expect-mocha-snapshot or chai-jest-snapshot) all don't support property matching, so you can't use things like I was looking into how to add this functionality, and it seems fairly straight forward. I need to add utils and equals to the .bind() object, and then it works, except there's no "proper" way to get access to
Right now, I'm using the hack suggested in this thread and it works... it really works!!! But it's so ugly it makes me feel a bit dirty. Can we please have equals exposed? Pretty please? I'm happy to raise a PR but not sure what's preferable - adding jasmineUtils to the exports in package.json, or exporting equals from expect? Thanks for listening, and for making jest so modular ❤️ |
Hi @ErisDS, and thanks for the detailed use case! I'll be adding a separate |
- this was copy-pasta'd direct from github: jestjs/jest#11867 - it works, but contains an unreachable code path that gets flagged up by coverage - the path might be reachable in some really bizzare circumstances with expect but then I would guess we'd get other worse errors than equals not being a function!
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. |
🚀 Feature Proposal
Slightly popular package jest-when(https://www.npmjs.com/package/jest-when) that depend on "expect" use portion of private api
require('expect/build/jasmineUtils')
I just raised PR to use jest as peer timkindberg/jest-when#84We would like to ask jest to expose "equals" from jasmineUtils or provide suitable API to get current equals matcher.
Motivation
Example
No response
Pitch
See above motivation. Either expose equals or provide jest-when compatible functionality in core.
The text was updated successfully, but these errors were encountered: