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.

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:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
lazarljubenoviccommented, Mar 1, 2022

Types from @types/jest have

    interface DoneCallback {
        (...args: any[]): any;
        fail(error?: string | { message: string }): any;
    }

Is this incorrect? Should the fail be removed?

0reactions
github-actions[bot]commented, Apr 2, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jquery ajax done function not firing - Stack Overflow
You need to chain the done() and fail() functions, they are not part of the options object used in $.ajax :
Read more >
On a .post, why isn't my .done(), .fail(), and .always() methods ...
Currently I am running on the same Application server and using the same port. I will look into adding CORS headers to give...
Read more >
jQuery Tutorial => jQuery ajax() success, error VS .done(), .fail()
success and Error : A success callback that gets invoked upon successful completion ... .ajax().done(function(data, textStatus, jqXHR){}); Replaces methodĀ ...
Read more >
Testing Asynchronous Code - Jest
Otherwise, a fulfilled promise would not fail the test. ... Jest will throw an error, if the same test function is passed a...
Read more >
The Simplest Thing Possible: Promises in JavaScript
This is accomplished by supplying a callback function. ... childQueries) .fail(function (response) { var html = "A problem was encountered.
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