Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New error "Did you forget to return or await the result of expectAsync" is misleading in some cases. #1854

Open
rubenlg opened this issue Sep 8, 2020 · 1 comment

Comments

@rubenlg
Copy link

@rubenlg rubenlg commented Sep 8, 2020

An asynchronous test case that uses both expectAsync and done can fail because done finishes the test before the asynchronous code completes. Awaiting the result of expectAsync doesn't help if the asynchronous part takes longer than the call to done. The error being displayed when running Jasmine doesn't mention this possibility, making the developer focus on the wrong thing.

Expected Behavior

The error would also mention the possibility of calling done() before expectAsync has completed.

Current Behavior

The error only hints at forgetting to return/await expectAsync.

Possible Solution

Extend the error message with another line, e.g:

Did you forget to return or await the result of expectAsync?
Did you call done() before expectAsync had a chance to complete?

Suite that reproduces the behavior (for bugs)

describe("sample",() => {
  it('sample', async done => {
    setTimeout(() => {
      done();
    });
    await expectAsync(somethingThatTakesLongerThanSetTimeout).toBeRejected();
  });
});

Context

Combining an async test case with done() is hopefully very rare, but it happens, especially when combining XHR with events in a single test case.

Your Environment

  • Version used: 3.6.0
  • Environment name and version (e.g. Chrome 39, node.js 5.4): Chrome 84
  • Operating System and version (desktop or mobile): Ubuntu Linux desktop
  • Link to your project: N/A
@slackersoft
Copy link
Member

@slackersoft slackersoft commented Sep 10, 2020

You really shouldn't be mixing the two async styles in a single test. One of them has to win, and the best Jasmine can do is probably just wait for the first one to happen. Currently, Jasmine has the done callback take precedence over any Promise/async stuff that might also be happening, because that is something that has to be determined before the function is actually invoked. It might make sense to include some wording about done in that error, but it shouldn't be quite so specific to expectAsync as this just has to do with having an expectation after done() is called.

I would be happy to review a pull request to add a note about calling done before actually being done with the test to that error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.