eslint-plugin-jest
Advanced tools
Comparing version 21.21.0 to 21.22.0
@@ -10,6 +10,4 @@ # Enforce assertion to be made in a test body (expect-expect) | ||
### Default configuration | ||
Examples of **incorrect** code for this rule: | ||
The following patterns are considered warnings: | ||
```js | ||
@@ -22,3 +20,3 @@ it('should be a test', () => { | ||
The following patterns are not warnings: | ||
Examples of **correct** code for this rule: | ||
@@ -33,1 +31,50 @@ ```js | ||
``` | ||
## Options | ||
```json | ||
{ | ||
"jest/expect-expect": [ | ||
"error", | ||
{ | ||
"assertFunctionNames": ["expect"] | ||
} | ||
] | ||
} | ||
``` | ||
### `assertFunctionNames` | ||
This array option whitelists the assertion function names to look for. | ||
Examples of **incorrect** code for the `{ "assertFunctionNames": ["expect"] }` | ||
option: | ||
```js | ||
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect"] }] */ | ||
import { expectSaga } from 'redux-saga-test-plan'; | ||
import { addSaga } from '../src/sagas'; | ||
test('returns sum', () => { | ||
expectSaga(addSaga, 1, 1) | ||
.returns(2) | ||
.run(); | ||
}); | ||
``` | ||
Examples of **correct** code for the | ||
`{ "assertFunctionNames": ["expect", "expectSaga"] }` option: | ||
```js | ||
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "expectSaga"] }] */ | ||
import { expectSaga } from 'redux-saga-test-plan'; | ||
import { addSaga } from '../src/sagas'; | ||
test('returns sum', () => { | ||
expectSaga(addSaga, 1, 1) | ||
.returns(2) | ||
.run(); | ||
}); | ||
``` |
{ | ||
"name": "eslint-plugin-jest", | ||
"version": "21.21.0", | ||
"version": "21.22.0", | ||
"description": "Eslint rules for Jest", | ||
@@ -5,0 +5,0 @@ "repository": "jest-community/eslint-plugin-jest", |
@@ -17,2 +17,11 @@ 'use strict'; | ||
'it("should pass", () => somePromise().then(() => expect(true).toBeDefined()))', | ||
{ | ||
code: | ||
'test("should pass", () => { expect(true).toBeDefined(); foo(true).toBe(true); })', | ||
options: [{ assertFunctionNames: ['expect', 'foo'] }], | ||
}, | ||
{ | ||
code: 'it("should return undefined",() => expectSaga(mySaga).returns());', | ||
options: [{ assertFunctionNames: ['expectSaga'] }], | ||
}, | ||
], | ||
@@ -48,3 +57,23 @@ | ||
}, | ||
{ | ||
code: 'test("should fail", () => { foo(true).toBe(true); })', | ||
options: [{ assertFunctionNames: ['expect'] }], | ||
errors: [ | ||
{ | ||
message: 'Test has no assertions', | ||
type: 'CallExpression', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: 'it("should also fail",() => expectSaga(mySaga).returns());', | ||
options: [{ assertFunctionNames: ['expect'] }], | ||
errors: [ | ||
{ | ||
message: 'Test has no assertions', | ||
type: 'CallExpression', | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
@@ -15,2 +15,14 @@ 'use strict'; | ||
}, | ||
schema: [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
assertFunctionNames: { | ||
type: 'array', | ||
items: [{ type: 'string' }], | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
], | ||
}, | ||
@@ -20,2 +32,6 @@ create(context) { | ||
const unchecked = []; | ||
const assertFunctionNames = | ||
context.options[0] && context.options[0].assertFunctionNames | ||
? context.options[0].assertFunctionNames | ||
: ['expect']; | ||
@@ -28,4 +44,4 @@ //---------------------------------------------------------------------- | ||
node.type === 'CallExpression' && | ||
// if we're not calling expect, ignore | ||
node.callee.name === 'expect'; | ||
// if we're not calling allowed assertion | ||
assertFunctionNames.some(name => name === node.callee.name); | ||
//---------------------------------------------------------------------- | ||
@@ -32,0 +48,0 @@ // Public |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
151621
4280