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

expectAsyncConsoleError not throwing error #28438

Open
zhouyx opened this issue May 15, 2020 · 7 comments
Open

expectAsyncConsoleError not throwing error #28438

zhouyx opened this issue May 15, 2020 · 7 comments

Comments

@zhouyx
Copy link
Contributor

zhouyx commented May 15, 2020

I tried to use the expectAsyncConsoleError() method, but it's not failing a unit test as I expected. Am I missing anything?

Here's my fake test (#28439 is the draft PR)

describe('test', () => {
  afterEach(() => {
    console.log('done');
  });
  it('my fake test', () => {
    expectAsyncConsoleError('fake message');
  });
});

The test passed. Got
image

When I tried to debug it, I noticed the test was run twice and failed the second time.
image

@zhouyx
Copy link
Contributor Author

zhouyx commented May 15, 2020

cc @micajuine-ho

@rsimha
Copy link
Contributor

rsimha commented May 15, 2020

@zhouyx The source of this bug is #20091, but the root cause lies in mochajs/mocha#1635. Here's my understanding of what is going on:

The only option I can think of is to go back to throw new Error(...) in afterEach (revert #20091), but this will halt all tests when the first violation of expectAsyncConsoleError is encountered. Is this acceptable to you?

@zhouyx
Copy link
Contributor Author

zhouyx commented May 15, 2020

Thank you @rsimha for the detailed explanation. Sign...
I find #20091 to be very useful. Killing karma due to a failing test sounds bad.

Can we avoid verifying the console error in afterEach() block? What about having expectAsyncConsoleError() to return a promise and request individual test to wait for that promise to be resolved.

@rsimha
Copy link
Contributor

rsimha commented May 15, 2020

I find #20091 to be very useful. Killing karma due to a failing test sounds bad.

Totally agree!

Can we avoid verifying the console error in afterEach() block? What about having expectAsyncConsoleError() to return a promise and request individual test to wait for that promise to be resolved.

The original goal of making expectAsyncConsoleError a single-line call instead of a wrapper like allowConsoleError was to make tests easy to write. With your suggestion, will the usage of expectAsyncConsoleError effectively change to a wrapper that waits for the expected error? (All existing usage will need to be converted.)

In any case, I have no objections to your suggestion if it improves the correctness of the test framework. So if you have the bandwidth, go for it!

Related: #15609

@zhouyx
Copy link
Contributor Author

zhouyx commented May 15, 2020

Yes, all the existing usage will need to be converted. Some of them may silently fail today, will also need to fix that after the conversion.
Can be a good fixit week item : )

@rsimha rsimha added this to To do in `wg-infra` Fixit Week 2/2021 via automation Feb 22, 2021
@samouri
Copy link
Member

samouri commented Apr 28, 2021

I also ran into this issue today. Tracked it down to a bug in karma-mocha: karma-runner/karma-mocha#236.

@stale
Copy link

stale bot commented Sep 17, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Inactive for one year or more label Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants