`expect-expect` & `no-standalone-expect` when using `expect` in afterEach
See original GitHub issueExample Code
Sometimes I group my enzyme snapshot tests like this to avoid writing expect(shallowToJson(wrapper)).toMatchSnapshot()
repeatedly:
import React from 'react';
import { shallow } from 'enzyme';
import shallowToJson from 'enzyme-to-json';
import Component1 from './index';
describe('outputs the expected tree when', () => {
let wrapper;
test('prop1 is foo', () => {
wrapper = shallow((
<Component1 prop1="foo" />
));
});
test('prop1 is bar', () => {
wrapper = shallow((
<Component1 prop1="bar" />
));
});
afterEach(() => {
expect(shallowToJson(wrapper)).toMatchSnapshot();
});
});
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
and no-standalone-expect
, but they are incompatible with the pattern above.
• expect-expect
: my test
s don’t have an expect
(but afterEach
does)
• no-standalone-expect
: my expect
is not inside a test
(but is in an afterEach
of a describe
that contains test
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 remain test
and it
. Optional: "jest/no-standalone-expect": ["error", allowedBlocks: ['test', 'it', 'afterEach']]
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:6
Top GitHub Comments
+1 for the suggestion of adding the
allowedBlocks
, that would allow compatibility withjest-in-case
.Resolved via #1129