Sitelet https://web.archive.org/web/20201020180418/https://github.com/jasmine/jasmine/issues/1845
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

Async matchers should fail with a meaningful error message, not a timeout, when the promise is pending. #1845

Open
sgravrock opened this issue Aug 15, 2020 · 2 comments

Comments

@sgravrock
Copy link
Member

@sgravrock sgravrock commented Aug 15, 2020

The following spec fails with a timeout but should fail with a message that explains that a promise was expected to be resolved:

  it('should fail with something other than a timeout', function() {
    var p = new Promise(function() {});
    return expectAsync(p).toBeResolved();
  });

Most of the async matchers have this problem, with the notable exception of toBePending.

@aashigupta19
Copy link

@aashigupta19 aashigupta19 commented Aug 24, 2020

Heyy, I would like to work on this issue. May you please assign me this?
Also, can you please give me the initial details and how to start it off? @sgravrock @cfya

@sgravrock
Copy link
Member Author

@sgravrock sgravrock commented Aug 26, 2020

Thank you! I think a good starting point would be to look at the implementation of the toBePending matcher in src/core/matchers/async/toBePending.js. Notice how it uses Promise.race to determine whether the promise is still pending. I think a similar approach would work for the other async matchers, except that the logic would be different: fail if the promise is still pending, otherwise follow the existing logic in the matcher. For each of the affected async matchers, we should have a test that verifies that the matcher fails if the promise is pending. The tests for toBePending, in spec/core/matchers/async/toBePendingSpec.js, might be worth a look.

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.