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
Recently I found out that instead of repeating expect.hasAssertions() in each test, you can have a single beforeEach(expect.hasAssertions) call at the top of the file.
It would be great if prefer-expect-assertions could detect file-level beforeEach(expect.hasAssertions) call and NOT give warnings in this case.
Current behavior:
beforeEach(expect.hasAssertions);test("foo",()=>{// Warning: Every test should have either `expect.assertions(<number of assertions>)`// or `expect.hasAssertions()` as its first expression});
beforeEach(()=>{expect.hasAssertions();someOtherFunction();});test("foo",()=>{// Warning: Every test should have either `expect.assertions(<number of assertions>)`// or `expect.hasAssertions()` as its first expression});
Expected behavior:
beforeEach(expect.hasAssertions);test("foo",()=>{// No warnings});
beforeEach(()=>{expect.hasAssertions();someOtherFunction();});test("foo",()=>{// No warnings});
The text was updated successfully, but these errors were encountered:
I can do you one better: you can stick that beforeEach in a script to be called by jest via setupFilesAfterEnv - I do it in most of my projects when I'm just using expect.
Overall, I think I'm going to say "maybe" to this - I actually think we should get very close to being able to determine this, but have concerns over edge-cases and the complexity of the code it'd require.
Specifically, because we will have to track the nesting of each beforeEach relative to the test functions to cover i.e
Still I think it might be possible based on some of the logic we have in other rules that do similar tracking of nesting that we might be able to do it.
G-Rath
changed the title
prefer-expect-assertions - allow beforeEach(expect.hasAssertions)
[prefer-expect-assertions] allow beforeEach(expect.hasAssertions)Aug 13, 2021
Recently I found out that instead of repeating
expect.hasAssertions()
in each test, you can have a singlebeforeEach(expect.hasAssertions)
call at the top of the file.It would be great if
prefer-expect-assertions
could detect file-levelbeforeEach(expect.hasAssertions)
call and NOT give warnings in this case.Current behavior:
Expected behavior:
The text was updated successfully, but these errors were encountered: