question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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();
});
screen shot 2018-09-28 at 18 17 24

Expected behaviour

A pointer to the source and the message highlighted correctly.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
theotherdoncommented, Jan 14, 2019

@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.

1reaction
theotherdoncommented, Jan 19, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found