The current documentation contains the following example:
test('fetchData() rejects to be error', async () => {
const drinkOctopus = new Promise(() => {
throw new DisgustingFlavorError('yuck, octopus flavor');
});
await expect(drinkOctopus).rejects.toMatch('octopus');
});
Simplified slightly, this would be expected to pass:
it('throws an error', async () => {
const drinkOctopus = new Promise(() => {
throw new Error('yuck, octopus flavor');
});
await expect(drinkOctopus).rejects.toMatch('octopus');
});
Running this test in Jest v20.0.4 (node v8.0.0) produces an error:
Failed: expect(string)[.not].toMatch(expected)
string value must be a string.
Received:
object: [Error: yuck, octopus flavor]
The Promise is rejecting with an Error rather than a string, as it should, but Jest isn't handling this as expected.
We also discuss about this in https://github.com/facebook/jest/issues/3601 so it might be a dupe.
Yeah it seems like a dupe... Closing in favor of #3601
I wouldn't close this; while the solution is being discussed on #3601, I think a quick documentation change is needed ATM so this issue seems fit for that as it looks like not even a solution is proposed yet in that issue.
I think developers using the documentation should not be expected to find an issue in Github that tells them that the docs are wrong. So I propose to reopen this issue as: "Update the documentation to reflect current status of things".
Most helpful comment
I wouldn't close this; while the solution is being discussed on #3601, I think a quick documentation change is needed ATM so this issue seems fit for that as it looks like not even a solution is proposed yet in that issue.
I think developers using the documentation should not be expected to find an issue in Github that tells them that the docs are wrong. So I propose to reopen this issue as: "Update the documentation to reflect current status of things".