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: v24.3.5
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: v24.3.6
Choose a head ref
  • 11 commits
  • 29 files changed
  • 7 contributors

Commits on Apr 11, 2021

  1. chore(deps): lock file maintenance (#812)

    Co-authored-by: Renovate Bot <bot@renovateapp.com>
    renovate[bot] and renovate-bot authored Apr 11, 2021
    Copy the full SHA
    96dfa33 View commit details

Commits on Apr 12, 2021

  1. Copy the full SHA
    0ca3d39 View commit details
  2. Copy the full SHA
    fb5eb5e View commit details

Commits on Apr 14, 2021

  1. Copy the full SHA
    004a9cb View commit details

Commits on Apr 19, 2021

  1. Copy the full SHA
    913bc73 View commit details

Commits on Apr 21, 2021

  1. Copy the full SHA
    127c12a View commit details

Commits on Apr 25, 2021

  1. Copy the full SHA
    6536594 View commit details

Commits on Apr 26, 2021

  1. fix: improve handling of .each calls and with tagged literals (#814)

    * fix: improve handling of `.each` calls and with tagged literals
    
    * refactor(no-focused-tests): greatly deduplicate code
    
    * refactor: remove unneeded utils
    
    * refactor(no-standalone-expect): remove unneeded check
    
    * test(no-conditional-expect): add cases for `each()()`
    
    * test(no-test-return-statement): add cases for `each()()`
    
    * fix(no-if): support `each()()`
    G-Rath authored Apr 26, 2021
    Copy the full SHA
    040c605 View commit details
  2. Copy the full SHA
    1fee973 View commit details
  3. Copy the full SHA
    7b7a396 View commit details
  4. chore(release): 24.3.6 [skip ci]

    ## [24.3.6](v24.3.5...v24.3.6) (2021-04-26)
    
    ### Bug Fixes
    
    * **no-conditional-expect:** check for expects in `catch`s on promises ([#819](#819)) ([1fee973](1fee973))
    * **valid-expect:** support async `expect` in ternary statements ([#833](#833)) ([7b7a396](7b7a396))
    * improve handling of `.each` calls and with tagged literals ([#814](#814)) ([040c605](040c605))
    semantic-release-bot committed Apr 26, 2021
    Copy the full SHA
    4859391 View commit details
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ jobs:
id: yarn-cache
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"

- uses: actions/cache@v2.1.4
- uses: actions/cache@v2.1.5
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: yarn2-${{ hashFiles('yarn.lock') }}
@@ -48,7 +48,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
node-version: [10.x, 12.x, 14.x, 15.x, 16.x]
eslint-version: [5, 6, 7]
runs-on: ubuntu-latest

9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [24.3.6](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.5...v24.3.6) (2021-04-26)


### Bug Fixes

* **no-conditional-expect:** check for expects in `catch`s on promises ([#819](https://github.com/jest-community/eslint-plugin-jest/issues/819)) ([1fee973](https://github.com/jest-community/eslint-plugin-jest/commit/1fee973429a74c60b14eead6a335623b4349b5f2))
* **valid-expect:** support async `expect` in ternary statements ([#833](https://github.com/jest-community/eslint-plugin-jest/issues/833)) ([7b7a396](https://github.com/jest-community/eslint-plugin-jest/commit/7b7a396e12c46d3087b467227887ed64854480c0))
* improve handling of `.each` calls and with tagged literals ([#814](https://github.com/jest-community/eslint-plugin-jest/issues/814)) ([040c605](https://github.com/jest-community/eslint-plugin-jest/commit/040c605cf7929a00980b3fa58331cd78ac6274f6))

## [24.3.5](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.4...v24.3.5) (2021-04-10)


7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -214,6 +214,13 @@ ensure consistency and readability in jest test suites.

https://github.com/dangreenisrael/eslint-plugin-jest-formatting

### eslint-plugin-istanbul

A set of rules to enforce good practices for Istanbul, one of the code coverage
tools used by Jest.

https://github.com/istanbuljs/eslint-plugin-istanbul

[recommended]: https://img.shields.io/badge/-recommended-lightgrey.svg
[suggest]: https://img.shields.io/badge/-suggest-yellow.svg
[fixable]: https://img.shields.io/badge/-fixable-green.svg
4 changes: 2 additions & 2 deletions docs/rules/expect-expect.md
Original file line number Diff line number Diff line change
@@ -87,10 +87,10 @@ it('is money-like', () => {

Examples of **correct** code for working with the HTTP assertions library
[SuperTest](https://www.npmjs.com/package/supertest) with the
`{ "assertFunctionNames": ["expect", "request.*.expect"] }` option:
`{ "assertFunctionNames": ["expect", "request.**.expect"] }` option:

```js
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "request.*.expect"] }] */
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "request.**.expect"] }] */
const request = require('supertest');
const express = require('express');

11 changes: 11 additions & 0 deletions docs/rules/no-conditional-expect.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,9 @@
This rule prevents the use of `expect` in conditional blocks, such as `if`s &
`catch`s.

This includes using `expect` in callbacks to functions named `catch`, which are
assumed to be promises.

## Rule Details

Jest considered a test to have failed if it throws an error, rather than on if
@@ -37,6 +40,10 @@ it('baz', async () => {
expect(err).toMatchObject({ code: 'MODULE_NOT_FOUND' });
}
});

it('throws an error', async () => {
await foo().catch(error => expect(error).toBeInstanceOf(error));
});
```

The following patterns are not warnings:
@@ -67,4 +74,8 @@ it('validates the request', () => {
expect(validRequest).toHaveBeenCalledWith(request);
}
});

it('throws an error', async () => {
await expect(foo).rejects.toThrow(Error);
});
```
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": "24.3.5",
"version": "24.3.6",
"description": "Eslint rules for Jest",
"keywords": [
"eslint",
4 changes: 2 additions & 2 deletions src/rules/__tests__/lowercase-name.test.ts
Original file line number Diff line number Diff line change
@@ -191,7 +191,7 @@ ruleTester.run('lowercase-name', rule, {
{
messageId: 'unexpectedLowercase',
data: { method: TestCaseName.it },
column: 9,
column: 29,
line: 1,
},
],
@@ -203,7 +203,7 @@ ruleTester.run('lowercase-name', rule, {
{
messageId: 'unexpectedLowercase',
data: { method: DescribeAlias.describe },
column: 15,
column: 35,
line: 1,
},
],
171 changes: 171 additions & 0 deletions src/rules/__tests__/no-conditional-expect.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TSESLint } from '@typescript-eslint/experimental-utils';
import dedent from 'dedent';
import resolveFrom from 'resolve-from';
import rule from '../no-conditional-expect';

@@ -151,6 +152,14 @@ ruleTester.run('logical conditions', rule, {
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: `
it.each()('foo', () => {
something || expect(something).toHaveBeenCalled();
})
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: `
function getValue() {
@@ -218,6 +227,14 @@ ruleTester.run('conditional conditions', rule, {
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: `
it.each()('foo', () => {
something ? noop() : expect(something).toHaveBeenCalled();
})
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: `
function getValue() {
@@ -304,6 +321,19 @@ ruleTester.run('switch conditions', rule, {
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: `
it.each()('foo', () => {
switch(something) {
case 'value':
expect(something).toHaveBeenCalled();
default:
break;
}
})
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: `
function getValue() {
@@ -384,6 +414,18 @@ ruleTester.run('if conditions', rule, {
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: `
it.each()('foo', () => {
if(!doSomething) {
// do nothing
} else {
expect(something).toHaveBeenCalled();
}
})
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: `
function getValue() {
@@ -491,6 +533,18 @@ ruleTester.run('catch conditions', rule, {
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: `
it.each()('foo', () => {
try {
} catch (err) {
expect(err).toMatch('Error');
}
})
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: `
it.skip.each\`\`('foo', () => {
@@ -503,6 +557,18 @@ ruleTester.run('catch conditions', rule, {
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: `
it.skip.each()('foo', () => {
try {
} catch (err) {
expect(err).toMatch('Error');
}
})
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: `
function getValue() {
@@ -519,3 +585,108 @@ ruleTester.run('catch conditions', rule, {
},
],
});

ruleTester.run('promises', rule, {
valid: [
`
it('works', async () => {
try {
await Promise.resolve().then(() => {
throw new Error('oh noes!');
});
} catch {
// ignore errors
} finally {
expect(something).toHaveBeenCalled();
}
});
`,
`
it('works', async () => {
await doSomething().catch(error => error);
expect(error).toBeInstanceOf(Error);
});
`,
`
it('works', async () => {
try {
await Promise.resolve().then(() => {
throw new Error('oh noes!');
});
} catch {
// ignore errors
}
expect(something).toHaveBeenCalled();
});
`,
],
invalid: [
{
code: dedent`
it('works', async () => {
await Promise.resolve()
.then(() => { throw new Error('oh noes!'); })
.catch(error => expect(error).toBeInstanceOf(Error));
});
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: dedent`
it('works', async () => {
await Promise.resolve()
.then(() => { throw new Error('oh noes!'); })
.catch(error => expect(error).toBeInstanceOf(Error))
.then(() => { throw new Error('oh noes!'); })
.catch(error => expect(error).toBeInstanceOf(Error))
.then(() => { throw new Error('oh noes!'); })
.catch(error => expect(error).toBeInstanceOf(Error));
});
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: dedent`
it('works', async () => {
await Promise.resolve()
.catch(error => expect(error).toBeInstanceOf(Error))
.catch(error => expect(error).toBeInstanceOf(Error))
.catch(error => expect(error).toBeInstanceOf(Error));
});
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: dedent`
it('works', async () => {
await Promise.resolve()
.catch(error => expect(error).toBeInstanceOf(Error))
.then(() => { throw new Error('oh noes!'); })
.then(() => { throw new Error('oh noes!'); })
.then(() => { throw new Error('oh noes!'); });
});
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: dedent`
it('works', async () => {
await somePromise
.then(() => { throw new Error('oh noes!'); })
.catch(error => expect(error).toBeInstanceOf(Error));
});
`,
errors: [{ messageId: 'conditionalExpect' }],
},
{
code: dedent`
it('works', async () => {
await somePromise.catch(error => expect(error).toBeInstanceOf(Error));
});
`,
errors: [{ messageId: 'conditionalExpect' }],
},
],
});
Loading