Done.fail function is not working
See original GitHub issueš Bug Report
Iām trying to use done.fail(āReasonā) to force fail asynchronous tests in my project but Iām getting the error:
FAIL project/src/testA/testA.spec.ts
ā Test A - Basic test suite āŗ should work
TypeError: done.fail is not a function
6 | it('should work', (done) => {
7 | expect(true).toBe(true);
> 8 | done.fail('Error');
| ^
9 |
10 | // promiseTimeout().then(() => {
11 | // });
at Object.done (project/src/testA/testA.spec.ts:8:14)
Iām using the latest version of Jest as for today (27.0.6), and Typescript with Babel. I donāt find the use of the ādone.fail()ā function at the official documentation but there are lots of resources that mention it, in Jasmine is done by using the same function and in @types/jest I can find the DoneCallback interface that specifies the fail(string) function.
@types/jest -> index.d.ts -> Line 329
interface DoneCallback {
(...args: any[]): any;
fail(error?: string | { message: string }): any;
}
To Reproduce
Use done.fail(āFailure reasonā) in a test using Jest.
Expected behavior
When done.fail(reason) is called the test should be forced to fail and show at the reporter the reason passed as an argument for the error message.
Link to repl or repo (highly encouraged)
I uploaded a simple project that is currently throwing the error: https://github.com/manuman94/jest-done-fail
envinfo
Iām using the latest version of Jest as for today (27.0.6), and Typescript with Babel
System:
OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
CPU: (8) x64 Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz
Binaries:
Node: 10.19.0 - /usr/local/bin/node
Yarn: 1.22.5 - /usr/bin/yarn
npm: 6.13.7 - /usr/local/bin/npm
npmPackages:
jest: ^27.0.6 => 27.0.6
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
Types from
@types/jest
haveIs this incorrect? Should the
fail
be removed?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. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.