You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
expect.hasAssertions() should only report an issue when the test is passing.
Motivation
When the JavaScript code fails due to an error, it causes double output with Jest. For example, the following test:
it('fails the test',()=>{thrownewError('woops!');expect(true).toBe(true);});
Produces this output:
● .CONTENT_NUMBER_REGEX › fails the test
woops!
5 |
6 | fit('fails the test', () => {
> 7 | throw new Error('woops!');
| ^
8 |
9 | expect(true).toBe(true);
10 | });
at Object.<anonymous> (spec/javascript/constants_spec.ts:7:11)
at runMicrotasks (<anonymous>)
● .CONTENT_NUMBER_REGEX › fails the test
expect.hasAssertions()
Expected at least one assertion to be called but received none.
44 |
45 | beforeEach(() => {
> 46 | expect.hasAssertions();
| ^
47 | });
48 |
49 | afterEach(() => {
at Object.<anonymous> (spec/javascript/test_helper.ts:46:10)
at runMicrotasks (<anonymous>)
If you're running your tests in a tiny VSCode pane, all you see is the hasAssertions() error which is a red herring. You need to scroll up to see the real error.
Example
Instead of displaying the hasAssertions error, when the test is already failing we should only see the relevant failure:
● .CONTENT_NUMBER_REGEX › fails the test
woops!
5 |
6 | fit('fails the test', () => {
> 7 | throw new Error('woops!');
| ^
8 |
9 | expect(true).toBe(true);
10 | });
at Object.<anonymous> (spec/javascript/constants_spec.ts:7:11)
at runMicrotasks (<anonymous>)
Pitch
Because the hasAssertions() option is part of the Jest core platform, it seems like this makes sense to address there as well.
The text was updated successfully, but these errors were encountered:
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
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.
🚀 Feature Proposal
expect.hasAssertions()
should only report an issue when the test is passing.Motivation
When the JavaScript code fails due to an error, it causes double output with Jest. For example, the following test:
Produces this output:
If you're running your tests in a tiny VSCode pane, all you see is the
hasAssertions()
error which is a red herring. You need to scroll up to see the real error.Example
Instead of displaying the
hasAssertions
error, when the test is already failing we should only see the relevant failure:Pitch
Because the
hasAssertions()
option is part of the Jest core platform, it seems like this makes sense to address there as well.The text was updated successfully, but these errors were encountered: