Socket
Socket
Sign inDemoInstall

eslint-plugin-jest

Package Overview
Dependencies
Maintainers
11
Versions
325
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-jest - npm Package Compare versions

Comparing version 25.1.0 to 25.2.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [25.2.0](https://github.com/jest-community/eslint-plugin-jest/compare/v25.1.0...v25.2.0) (2021-10-14)
### Features
* **expect-expect:** support `additionalTestBlockFunctions` option ([#850](https://github.com/jest-community/eslint-plugin-jest/issues/850)) ([3b94c62](https://github.com/jest-community/eslint-plugin-jest/commit/3b94c62b81a50bc8b213c597bb59799cff1ef207))
# [25.1.0](https://github.com/jest-community/eslint-plugin-jest/compare/v25.0.6...v25.1.0) (2021-10-14)

@@ -2,0 +9,0 @@

43

docs/rules/expect-expect.md

@@ -37,3 +37,4 @@ # Enforce assertion to be made in a test body (`expect-expect`)

{
"assertFunctionNames": ["expect"]
"assertFunctionNames": ["expect"],
"additionalTestBlockFunctions": []
}

@@ -106,1 +107,41 @@ ]

```
### `additionalTestBlockFunctions`
This array can be used to specify the names of functions that should also be
treated as test blocks:
```json
{
"rules": {
"jest/expect-expect": [
"error",
{ "additionalTestBlockFunctions": ["theoretically"] }
]
}
}
```
The following is _correct_ when using the above configuration:
```js
import theoretically from 'jest-theories';
describe('NumberToLongString', () => {
const theories = [
{ input: 100, expected: 'One hundred' },
{ input: 1000, expected: 'One thousand' },
{ input: 10000, expected: 'Ten thousand' },
{ input: 100000, expected: 'One hundred thousand' },
];
theoretically(
'the number {input} is correctly translated to string',
theories,
theory => {
const output = NumberToLongString(theory.input);
expect(output).toBe(theory.expected);
},
);
});
```

20

lib/rules/expect-expect.js

@@ -50,2 +50,8 @@ "use strict";

}]
},
additionalTestBlockFunctions: {
type: 'array',
items: {
type: 'string'
}
}

@@ -58,7 +64,9 @@ },

defaultOptions: [{
assertFunctionNames: ['expect']
assertFunctionNames: ['expect'],
additionalTestBlockFunctions: []
}],
create(context, [{
assertFunctionNames = ['expect']
assertFunctionNames = ['expect'],
additionalTestBlockFunctions = []
}]) {

@@ -86,7 +94,9 @@ const unchecked = [];

CallExpression(node) {
const name = (0, _utils.getNodeName)(node.callee);
var _getNodeName;
if (name === _utils.TestCaseName.it || name === _utils.TestCaseName.test) {
const name = (_getNodeName = (0, _utils.getNodeName)(node.callee)) !== null && _getNodeName !== void 0 ? _getNodeName : '';
if ((0, _utils.isTestCaseCall)(node) || additionalTestBlockFunctions.includes(name)) {
unchecked.push(node);
} else if (name && matchesAssertFunctionName(name, assertFunctionNames)) {
} else if (matchesAssertFunctionName(name, assertFunctionNames)) {
// Return early in case of nested `it` statements.

@@ -93,0 +103,0 @@ checkCallExpressionUsed(context.getAncestors());

{
"name": "eslint-plugin-jest",
"version": "25.1.0",
"version": "25.2.0",
"description": "Eslint rules for Jest",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc