Incorrect custom async matcher error message
See original GitHub issue🐛 Bug Report
Custom async matchers are throwing with an error message prefixed with Error
and not showing the source code of where the error originated from.
To Reproduce
Given the example in the docs, I get the following output:
expect.extend({
async toBeDivisibleByExternalValue(received) {
const externalValue = await Promise.resolve(1000);
const pass = received % externalValue == 0;
if (pass) {
return {
message: () =>
`expected ${received} not to be divisible by ${externalValue}`,
pass: true,
};
} else {
return {
message: () =>
`expected ${received} to be divisible by ${externalValue}`,
pass: false,
};
}
},
});
test('is divisible by external value', async () => {
await expect(100).toBeDivisibleByExternalValue();
await expect(101).not.toBeDivisibleByExternalValue();
});
Expected behaviour
A pointer to the source and the message highlighted correctly.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:17 (9 by maintainers)
Top Results From Across the Web
Override default jasmine error message for matchers
You have to write custom matchers for this. Because the error message is hard coded in jasmine. Share. Share a link to this...
Read more >How To Improve Your Tests with Custom Matchers
In this situation we could write our own custom Matcher toMatchTodo() that we ... completed: false, }); }); test('List all Todos ', async...
Read more >Expect - WebdriverIO
When you're writing tests, you often need to check that values meet certain conditions. expect gives you access to a number of "matchers"...
Read more >Jest Expect - w3resource
Matchers has to return an object (or a Promise of an object) with two keys. pass will indicate whether there was a match...
Read more >Custom Matchers · GitBook - GitHub Pages
Custom Matchers API · pass to indicates if the test passed · message a function with no arguments that returns an error message...
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
@SimenB Yes, I was able to make it work. I just have a couple of failing snapshots to update. I’m hoping to have the PR today or tomorrow.
@SimenB Thanks for the recommendation! 🙂 I just opened PR #7652 and also kept the refactoring to a minimum. (I’ll open a separate PR for the refactor once we merge this one.) I left a question for you regarding removing a couple of lines from the stack trace.