Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jest-community/eslint-plugin-jest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v28.1.0
Choose a base ref
...
head repository: jest-community/eslint-plugin-jest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v28.1.1
Choose a head ref
  • 2 commits
  • 4 files changed
  • 2 contributors

Commits on Apr 6, 2024

  1. fix(max-expects): properly reset counter when exiting a test case (#1550

    )
    G-Rath authored Apr 6, 2024
    Copy the full SHA
    b4b7cbc View commit details
  2. chore(release): 28.1.1 [skip ci]

    ## [28.1.1](v28.1.0...v28.1.1) (2024-04-06)
    
    ### Bug Fixes
    
    * **max-expects:** properly reset counter when exiting a test case ([#1550](#1550)) ([b4b7cbc](b4b7cbc))
    semantic-release-bot committed Apr 6, 2024
    Copy the full SHA
    8f59e2b View commit details
Showing with 241 additions and 1 deletion.
  1. +7 −0 CHANGELOG.md
  2. +1 −1 package.json
  3. +229 −0 src/rules/__tests__/max-expects.test.ts
  4. +4 −0 src/rules/max-expects.ts
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [28.1.1](https://github.com/jest-community/eslint-plugin-jest/compare/v28.1.0...v28.1.1) (2024-04-06)


### Bug Fixes

* **max-expects:** properly reset counter when exiting a test case ([#1550](https://github.com/jest-community/eslint-plugin-jest/issues/1550)) ([b4b7cbc](https://github.com/jest-community/eslint-plugin-jest/commit/b4b7cbc6195b47ba032fcf9ef1443de6b851d42b))

# [28.1.0](https://github.com/jest-community/eslint-plugin-jest/compare/v28.0.0...v28.1.0) (2024-04-06)


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-jest",
"version": "28.1.0",
"version": "28.1.1",
"description": "ESLint rules for Jest",
"keywords": [
"eslint",
229 changes: 229 additions & 0 deletions src/rules/__tests__/max-expects.test.ts
Original file line number Diff line number Diff line change
@@ -119,6 +119,39 @@ ruleTester.run('max-expects', rule, {
expect(true).toBeDefined();
});
`,
dedent`
test('should not pass', () => {
const checkValue = (value) => {
expect(value).toBeDefined();
expect(value).toBeDefined();
};
checkValue(true);
});
test('should not pass', () => {
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
});
`,
dedent`
test('should not pass', done => {
emitter.on('event', value => {
expect(value).toBeDefined();
expect(value).toBeDefined();
expect(value).toBeDefined();
expect(value).toBeDefined();
done();
});
});
test('should not pass', () => {
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
});
`,
dedent`
function myHelper() {
expect(true).toBeDefined();
@@ -204,6 +237,24 @@ ruleTester.run('max-expects', rule, {
},
],
},
{
code: dedent`
describe('given decimal places', () => {
it("test 1", fakeAsync(() => {
expect(true).toBeTrue();
expect(true).toBeTrue();
expect(true).toBeTrue();
}))
it("test 2", fakeAsync(() => {
expect(true).toBeTrue();
expect(true).toBeTrue();
expect(true).toBeTrue();
}))
})
`,
options: [{ max: 5 }],
},
],
invalid: [
{
@@ -314,6 +365,184 @@ ruleTester.run('max-expects', rule, {
},
],
},
{
code: dedent`
test('should not pass', () => {
const checkValue = (value) => {
expect(value).toBeDefined();
expect(value).toBeDefined();
};
checkValue(true);
});
test('should not pass', () => {
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
});
`,
options: [{ max: 1 }],
errors: [
{
messageId: 'exceededMaxAssertion',
line: 4,
column: 5,
},
{
messageId: 'exceededMaxAssertion',
line: 11,
column: 3,
},
{
messageId: 'exceededMaxAssertion',
line: 12,
column: 3,
},
],
},
{
code: dedent`
test('should not pass', () => {
const checkValue = (value) => {
expect(value).toBeDefined();
expect(value).toBeDefined();
};
checkValue(true);
});
test('should not pass', () => {
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
});
`,
options: [{ max: 2 }],
errors: [
{
messageId: 'exceededMaxAssertion',
line: 12,
column: 3,
},
],
},
{
code: dedent`
test('should not pass', () => {
const checkValue = (value) => {
expect(value).toBeDefined();
expect(value).toBeDefined();
};
expect(value).toBeDefined();
checkValue(true);
});
test('should not pass', () => {
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
});
`,
options: [{ max: 2 }],
errors: [
{
messageId: 'exceededMaxAssertion',
line: 13,
column: 3,
},
],
},
{
code: dedent`
test('should not pass', done => {
emitter.on('event', value => {
expect(value).toBeDefined();
expect(value).toBeDefined();
done();
});
});
test('should not pass', () => {
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
});
`,
options: [{ max: 1 }],
errors: [
{
messageId: 'exceededMaxAssertion',
line: 4,
column: 5,
},
{
messageId: 'exceededMaxAssertion',
line: 11,
column: 3,
},
{
messageId: 'exceededMaxAssertion',
line: 12,
column: 3,
},
],
},
{
code: dedent`
test('should not pass', done => {
emitter.on('event', value => {
expect(value).toBeDefined();
expect(value).toBeDefined();
done();
});
});
test('should not pass', () => {
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
});
`,
options: [{ max: 2 }],
errors: [
{
messageId: 'exceededMaxAssertion',
line: 12,
column: 3,
},
],
},
{
code: dedent`
describe('given decimal places', () => {
it("test 1", fakeAsync(() => {
expect(true).toBeTrue();
expect(true).toBeTrue();
expect(true).toBeTrue();
}))
it("test 2", fakeAsync(() => {
expect(true).toBeTrue();
expect(true).toBeTrue();
expect(true).toBeTrue();
expect(true).toBeTrue();
expect(true).toBeTrue();
}))
})
`,
options: [{ max: 3 }],
errors: [
{
messageId: 'exceededMaxAssertion',
line: 12,
column: 5,
},
{
messageId: 'exceededMaxAssertion',
line: 13,
column: 5,
},
],
},
{
code: dedent`
describe('test', () => {
4 changes: 4 additions & 0 deletions src/rules/max-expects.ts
Original file line number Diff line number Diff line change
@@ -52,6 +52,10 @@ export default createRule({
CallExpression(node) {
const jestFnCall = parseJestFnCall(node, context);

if (jestFnCall?.type === 'test') {
count = 0;
}

if (
jestFnCall?.type !== 'expect' ||
jestFnCall.head.node.parent?.type === AST_NODE_TYPES.MemberExpression