Chainable asymmetric matchers
See original GitHub issueDo you want to request a feature or report a bug?
feature
What is the current behavior?
expect({ foo: new Error("failure") }).toEqual({
foo: expect.any(Error).objectContaining({ message: "failure" }),
})
outputs
TypeError: expect.any(...).objectContaining is not a function
548 | foo: new Error("failure"),
549 | }).toEqual({
> 550 | foo: expect.any(Error).objectContaining({ message: "failure" }),
551 | })
552 | })
553 |
What is the expected behavior?
The syntax above should not throw.
The following test should throw a descriptive error message:
expect({ foo: new Error("failure") }).toEqual({
foo: expect.any(Error).objectContaining({ message: "success" }),
})
Please provide your exact Jest configuration
{
"testMatch": [
"<rootDir>/imports/**/*.test.js"
],
"testPathIgnorePatterns": [
"/node_modules/",
"/.meteor"
],
"setupTestFrameworkScriptFile": "./imports/test-helpers/setup.js",
"coverageDirectory": "imports/coverage"
}
Run npx envinfo --preset jest
in your project directory and paste the
results here
System:
OS: macOS High Sierra 10.13.3
CPU: x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
Binaries:
Node: 8.9.1
Yarn: 1.5.1
npm: 5.5.1
npmPackages:
jest:
wanted: ^22.4.2
installed: 22.4.2
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:16 (10 by maintainers)
Top Results From Across the Web
Practical Guide to Custom Jest Matchers - Redd Developer
There are two types of matchers in Jest: symmetric and asymmetric. ... But it's the .not. chain that makes this assertion inverted, ...
Read more >Chain Jest Matchers together To Create one Powerful Assertion
Chain core and custom matchers together. ... Note: jest-chain does not currently support asymmetric matcher chaining, if you want this please send a...
Read more >Your first suite - Jasmine Documentation
Any matcher can evaluate to a negative assertion by chaining the call to expect with a not ... Jasmine provides a number of...
Read more >The hidden power of Jest matchers | by Boris - Medium
Basically, it means that if the right-side object has an asymmetricMatch method, the result if its call will be used instead of an...
Read more >2D Side‐Chain Engineered Asymmetric Acceptors ...
Abstract The charge transport and morphology of active layers are key considerations for device performance and stability in organic solar ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A few things I would like to confirm before coding:
Implementation
In order to have a nice implementation, I suggest:
1/ creating a “combine” operation for asymmetric matchers:
2/ adding the chaining API itself
Descriptive error message
I imagined printing the first failing assertion : what do you think?
That’s a separate conversation entirely. I don’t think it provides a lot of value for the added complexity and it can make assertions harder to read rather than easier.
The nice thing about the extension to asymmetric matchers here is that it allows to create a richer description of what you’d like to match. However, I think we need to be careful if we add this to Jest:
expect.arrayContaining(…).stringMatching()
and similar combinations do not make any sense.