-
Notifications
You must be signed in to change notification settings - Fork 237
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
expect-expect
& no-standalone-expect
when using expect
in afterEach
#534
Comments
I was about to open a similar ticket, but I found yours. I am having a different scenario, but similar issue. We added this library to for our tests https://www.npmjs.com/package/jest-theories, so our tests now run inside Because of this we had to disable |
+1 for the suggestion of adding the |
Was this implemented by #585? To allow "jest/no-standalone-expect": [
"error",
{
"additionalTestBlockFunctions": [
"beforeAll",
"beforeEach",
"afterEach",
"afterAll"
]
}
] And then Safe to close? |
But turning off |
So I'm about to make a PR for adding Personally I'd recommend looking to alias the methods instead, which which would solve this problem:
You should be able to set this up in a setup file so you wouldn't need to do it in every test. (In saying that, we do want to support being able to define which methods are actually considered test methods as a config that's used by each rule, which thinking about it should probably be accompanied by a rule-level override + some consistent properties; so you will be able to do this eventually) |
Resolved via #1129 |
Example Code
Sometimes I group my enzyme snapshot tests like this to avoid writing
expect(shallowToJson(wrapper)).toMatchSnapshot()
repeatedly:The tests are often times more complex than ^ with which props are being passed.
Problem
There are two
eslint-plugin-jest
rules that I'd like to use,expect-expect
andno-standalone-expect
, but they are incompatible with the pattern above.•
expect-expect
: mytest
s don't have anexpect
(butafterEach
does)•
no-standalone-expect
: myexpect
is not inside atest
(but is in anafterEach
of adescribe
that containstest
s)Proposed solution
Could the two rules be modified to allow the above use case?
no-standalone-expect
could have options for which blocks are valid. Default could remaintest
andit
. Optional:"jest/no-standalone-expect": ["error", allowedBlocks: ['test', 'it', 'afterEach']]
The text was updated successfully, but these errors were encountered: