Socket
Socket
Sign inDemoInstall

eslint-plugin-jest-dom

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-jest-dom - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

docs/rules/prefer-to-have-text-content.md

7

.eslintrc.json

@@ -9,3 +9,2 @@ {

"node": true
// "jest/globals": true
},

@@ -17,8 +16,8 @@ "plugins": [

"extends": [
"plugin:eslint-plugin/recommended"
"plugin:eslint-plugin/recommended",
"prettier"
],
"rules": {
"prettier/prettier": "error",
"no-var": "error"
}
}
}

@@ -1,10 +0,10 @@

'use strict';
"use strict";
const fs = require('fs');
const path = require('path');
const rules = require('..').rules;
const fs = require("fs");
const path = require("path");
const rules = require("..").rules;
const README_LOCATION = path.resolve(__dirname, '..', 'README.md');
const BEGIN_TABLE_MARKER = '<!-- __BEGIN AUTOGENERATED TABLE__ -->\n';
const END_TABLE_MARKER = '\n<!-- __END AUTOGENERATED TABLE__ -->';
const README_LOCATION = path.resolve(__dirname, "..", "README.md");
const BEGIN_TABLE_MARKER = "<!-- __BEGIN AUTOGENERATED TABLE__ -->\n";
const END_TABLE_MARKER = "\n<!-- __END AUTOGENERATED TABLE__ -->";

@@ -20,6 +20,6 @@ const expectedTableLines = Object.keys(rules)

`[${ruleId}](https://github.com/testing-library/eslint-plugin-jest-dom/blob/master/docs/rules/${ruleId}.md)`,
rule.meta.docs.recommended ? '✔️' : '',
rule.meta.fixable ? '🛠' : '',
rule.meta.docs.description,
].join(' | ')
rule.meta.docs.recommended ? "✔️" : "",
rule.meta.fixable ? "🛠" : "",
rule.meta.docs.description
].join(" | ")
);

@@ -29,7 +29,7 @@

},
['Name | ✔️ | 🛠 | Description', '----- | ----- | ----- | -----']
["Name | ✔️ | 🛠 | Description", "----- | ----- | ----- | -----"]
)
.join('\n');
.join("\n");
const readmeContents = fs.readFileSync(README_LOCATION, 'utf8');
const readmeContents = fs.readFileSync(README_LOCATION, "utf8");

@@ -36,0 +36,0 @@ if (!readmeContents.includes(BEGIN_TABLE_MARKER)) {

module.exports = {
testMatch: ['**/tests/**/*.js'],
testMatch: ["**/tests/**/*.js"],
collectCoverage: true,

@@ -9,7 +9,7 @@ coverageThreshold: {

lines: 98.97,
statements: 0,
},
statements: 0
}
},
testPathIgnorePatterns: ['<rootDir>/tests/fixtures/'],
collectCoverageFrom: ['lib/**/*.js', '!**/node_modules/**'],
testPathIgnorePatterns: ["<rootDir>/tests/fixtures/"],
collectCoverageFrom: ["lib/**/*.js", "!**/node_modules/**"]
};

@@ -5,3 +5,3 @@ module.exports = ({ preferred, negatedPreferred, attributes }) => context => {

node.arguments[1].value === true ||
node.arguments[1].value === '') &&
node.arguments[1].value === "") &&
!negated

@@ -19,3 +19,3 @@ ? preferred

) {
if (negatedPreferred.startsWith('toBe')) {
if (negatedPreferred.startsWith("toBe")) {
const incorrectFunction = node.callee.property.name;

@@ -33,3 +33,3 @@

);
},
}
});

@@ -43,3 +43,3 @@ }

const {
arguments: [{ property, property: { name } = {} }],
arguments: [{ property, property: { name } = {} }]
} = node.callee.object;

@@ -50,4 +50,4 @@ const matcher = node.callee.property.name;

const isNegated =
matcher.endsWith('Falsy') ||
((matcher === 'toBe' || matcher === 'toEqual') &&
matcher.endsWith("Falsy") ||
((matcher === "toBe" || matcher === "toEqual") &&
matcherArg !== true);

@@ -67,5 +67,5 @@ const correctFunction = getCorrectFunctionFor(

`${correctFunction}()`
),
)
];
},
}
});

@@ -90,3 +90,3 @@ }

);
},
}
});

@@ -105,3 +105,3 @@ }

.map(({ raw }) => raw)
.join(', ')})`;
.join(", ")})`;
context.report({

@@ -115,9 +115,9 @@ node: node.callee.property,

`${correctFunction}()`
),
)
];
},
}
});
}
},
}
};
};

@@ -5,3 +5,3 @@ /**

*/
'use strict';
"use strict";

@@ -12,3 +12,3 @@ //------------------------------------------------------------------------------

let requireIndex = require('requireindex');
let requireIndex = require("requireindex");

@@ -20,3 +20,3 @@ //------------------------------------------------------------------------------

// import all rules in lib/rules
module.exports.rules = requireIndex(__dirname + '/rules');
module.exports.rules = requireIndex(__dirname + "/rules");

@@ -27,3 +27,3 @@ module.exports.generateRecommendedConfig = rules => {

rule.meta.docs.recommended
? { ...memo, [`jest-dom/${name}`]: 'error' }
? { ...memo, [`jest-dom/${name}`]: "error" }
: memo,

@@ -36,5 +36,5 @@ {}

recommended: {
plugins: ['jest-dom'],
rules: module.exports.generateRecommendedConfig(module.exports.rules),
},
plugins: ["jest-dom"],
rules: module.exports.generateRecommendedConfig(module.exports.rules)
}
};

@@ -5,5 +5,5 @@ /**

*/
'use strict';
"use strict";
const createBannedAttributeRule = require('../createBannedAttributeRule');
const createBannedAttributeRule = require("../createBannedAttributeRule");

@@ -13,15 +13,15 @@ module.exports = {

docs: {
description: 'prefer toBeChecked over checking attributes',
category: 'jest-dom',
description: "prefer toBeChecked over checking attributes",
category: "jest-dom",
recommended: true,
url: 'prefer-checked',
url: "prefer-checked"
},
fixable: 'code',
fixable: "code"
},
create: createBannedAttributeRule({
preferred: 'toBeChecked',
negatedPreferred: 'not.toBeChecked',
attributes: ['checked', 'aria-checked'],
}),
preferred: "toBeChecked",
negatedPreferred: "not.toBeChecked",
attributes: ["checked", "aria-checked"]
})
};

@@ -9,8 +9,8 @@ /**

docs: {
description: 'Prefer toBeEmpty over checking innerHTML',
category: 'jest-dom',
description: "Prefer toBeEmpty over checking innerHTML",
category: "jest-dom",
recommended: true,
url: 'prefer-empty',
url: "prefer-empty"
},
fixable: 'code', // or "code" or "whitespace"
fixable: "code" // or "code" or "whitespace"
},

@@ -25,3 +25,3 @@

node,
message: 'Use toBeEmpty instead of checking inner html.',
message: "Use toBeEmpty instead of checking inner html.",
fix(fixer) {

@@ -31,3 +31,3 @@ return [

node.left.property.range[0] - 1,
node.range[1],
node.range[1]
]),

@@ -37,9 +37,9 @@ fixer.replaceText(

!!node.parent.parent.parent.arguments[0].value ===
node.operator.startsWith('=') // binary expression XNOR matcher boolean
? 'toBeEmpty'
: 'not.toBeEmpty'
node.operator.startsWith("=") // binary expression XNOR matcher boolean
? "toBeEmpty"
: "not.toBeEmpty"
),
fixer.remove(node.parent.parent.parent.arguments[0]),
fixer.remove(node.parent.parent.parent.arguments[0])
];
},
}
});

@@ -52,3 +52,3 @@ },

node,
message: 'Use toBeEmpty instead of checking inner html.',
message: "Use toBeEmpty instead of checking inner html.",
fix(fixer) {

@@ -58,3 +58,3 @@ return [

node.left.property.range[0] - 1,
node.range[1],
node.range[1]
]),

@@ -64,9 +64,9 @@ fixer.replaceText(

!!node.parent.parent.parent.arguments[0].value ===
node.operator.startsWith('=') // binary expression XNOR matcher boolean
? 'toBeEmpty'
: 'not.toBeEmpty'
node.operator.startsWith("=") // binary expression XNOR matcher boolean
? "toBeEmpty"
: "not.toBeEmpty"
),
fixer.remove(node.parent.parent.parent.arguments[0]),
fixer.remove(node.parent.parent.parent.arguments[0])
];
},
}
});

@@ -80,3 +80,3 @@ },

node,
message: 'Use toBeEmpty instead of checking inner html.',
message: "Use toBeEmpty instead of checking inner html.",
fix(fixer) {

@@ -86,8 +86,8 @@ return [

node.property.range[0] - 1,
node.property.range[1],
node.property.range[1]
]),
fixer.replaceText(node.parent.parent.property, 'toBeEmpty'),
fixer.remove(node.parent.parent.parent.arguments[0]),
fixer.replaceText(node.parent.parent.property, "toBeEmpty"),
fixer.remove(node.parent.parent.parent.arguments[0])
];
},
}
});

@@ -102,3 +102,3 @@ }

node,
message: 'Use toBeEmpty instead of checking inner html.',
message: "Use toBeEmpty instead of checking inner html.",
fix(fixer) {

@@ -108,11 +108,11 @@ return [

node.property.range[0] - 1,
node.property.range[1],
node.property.range[1]
]),
fixer.replaceText(
node.parent.parent.parent.property,
'toBeEmpty'
"toBeEmpty"
),
fixer.remove(node.parent.parent.parent.parent.arguments[0]),
fixer.remove(node.parent.parent.parent.parent.arguments[0])
];
},
}
});

@@ -126,3 +126,3 @@ }

node,
message: 'Use toBeEmpty instead of checking inner html.',
message: "Use toBeEmpty instead of checking inner html.",
fix(fixer) {

@@ -132,7 +132,7 @@ return [

node.property.range[0] - 1,
node.property.range[1],
node.property.range[1]
]),
fixer.replaceText(node.parent.parent.property, 'toBeEmpty'),
fixer.replaceText(node.parent.parent.property, "toBeEmpty")
];
},
}
});

@@ -147,3 +147,3 @@ },

node,
message: 'Use toBeEmpty instead of checking inner html.',
message: "Use toBeEmpty instead of checking inner html.",
fix(fixer) {

@@ -153,11 +153,11 @@ return [

node.property.range[0] - 1,
node.property.range[1],
node.property.range[1]
]),
fixer.replaceText(
node.parent.parent.parent.property,
'toBeEmpty'
"toBeEmpty"
),
fixer.remove(node.parent.parent.parent.parent.arguments[0]),
fixer.remove(node.parent.parent.parent.parent.arguments[0])
];
},
}
});

@@ -172,3 +172,3 @@ }

node,
message: 'Use toBeEmpty instead of checking inner html.',
message: "Use toBeEmpty instead of checking inner html.",
fix(fixer) {

@@ -178,10 +178,7 @@ return [

node.property.range[0] - 1,
node.property.range[1],
node.property.range[1]
]),
fixer.replaceText(
node.parent.parent.parent.property,
'toBeEmpty'
),
fixer.replaceText(node.parent.parent.parent.property, "toBeEmpty")
];
},
}
});

@@ -195,3 +192,3 @@ },

node,
message: 'Use toBeEmpty instead of checking inner html.',
message: "Use toBeEmpty instead of checking inner html.",
fix(fixer) {

@@ -201,13 +198,13 @@ return [

node.property.range[0] - 1,
node.property.range[1],
node.property.range[1]
]),
fixer.replaceText(node.parent.parent.property, 'toBeEmpty'),
fixer.remove(node.parent.parent.parent.arguments[0]),
fixer.replaceText(node.parent.parent.property, "toBeEmpty"),
fixer.remove(node.parent.parent.parent.arguments[0])
];
},
}
});
}
},
}
};
},
}
};

@@ -5,5 +5,5 @@ /**

*/
'use strict';
"use strict";
const createBannedAttributeRule = require('../createBannedAttributeRule');
const createBannedAttributeRule = require("../createBannedAttributeRule");

@@ -14,15 +14,15 @@ module.exports = {

description:
'prefer toBeDisabled or toBeEnabled over checking attributes',
category: 'jest-dom',
"prefer toBeDisabled or toBeEnabled over checking attributes",
category: "jest-dom",
recommended: true,
url: 'prefer-enabled-disabled',
url: "prefer-enabled-disabled"
},
fixable: 'code',
fixable: "code"
},
create: createBannedAttributeRule({
preferred: 'toBeDisabled',
negatedPreferred: 'toBeEnabled',
attributes: ['disabled'],
}),
preferred: "toBeDisabled",
negatedPreferred: "toBeEnabled",
attributes: ["disabled"]
})
};

@@ -5,3 +5,3 @@ /**

*/
'use strict';
"use strict";

@@ -14,3 +14,3 @@ const variantsOfDoc = [

// global.window.document:
`[object.object.object.name='global'][object.object.property.name='window'][object.property.name=document]`,
`[object.object.object.name='global'][object.object.property.name='window'][object.property.name=document]`
];

@@ -21,7 +21,7 @@

docs: {
description: 'prefer toHaveFocus over checking document.activeElement',
category: 'jest-dom',
recommended: true,
description: "prefer toHaveFocus over checking document.activeElement",
category: "jest-dom",
recommended: true
},
fixable: 'code',
fixable: "code"
},

@@ -36,3 +36,3 @@

)
.join(', ')](node) {
.join(", ")](node) {
const element =

@@ -50,3 +50,3 @@ node.parent.parent.parent.parent.callee.parent.arguments[0];

fixer.remove(element),
fixer.replaceText(matcher, 'toHaveFocus'),
fixer.replaceText(matcher, "toHaveFocus")
];

@@ -58,7 +58,7 @@ } else {

[element.range[1], element.range[1] + 1],
'.not.toHaveFocus()'
),
".not.toHaveFocus()"
)
];
}
},
}
});

@@ -71,3 +71,3 @@ },

)
.join(', ')](node) {
.join(", ")](node) {
const matcher = node.parent.callee.property;

@@ -80,5 +80,5 @@ context.report({

fixer.remove(node),
fixer.replaceText(matcher, 'toHaveFocus'),
fixer.replaceText(matcher, "toHaveFocus")
];
},
}
});

@@ -91,3 +91,3 @@ },

)
.join(', ')](node) {
.join(", ")](node) {
const element = node.parent.parent.parent.arguments[0];

@@ -104,4 +104,4 @@ const matcher = node.parent.parent.property;

[element.range[1], element.range[1] + 1],
'.toHaveFocus()'
),
".toHaveFocus()"
)
];

@@ -112,5 +112,5 @@ }

fixer.remove(element),
fixer.replaceText(matcher, 'toHaveFocus'),
fixer.replaceText(matcher, "toHaveFocus")
];
},
}
});

@@ -123,3 +123,3 @@ },

)
.join(', ')](node) {
.join(", ")](node) {
const matcher = node.parent.callee.property;

@@ -132,9 +132,9 @@ context.report({

fixer.remove(node),
fixer.replaceText(matcher, 'toHaveFocus'),
fixer.replaceText(matcher, "toHaveFocus")
];
},
}
});
},
}
};
},
}
};

@@ -5,5 +5,5 @@ /**

*/
'use strict';
"use strict";
const createBannedAttributeRule = require('../createBannedAttributeRule');
const createBannedAttributeRule = require("../createBannedAttributeRule");

@@ -13,15 +13,15 @@ module.exports = {

docs: {
description: 'prefer toBeRequired over checking properties',
category: 'jest-dom',
description: "prefer toBeRequired over checking properties",
category: "jest-dom",
recommended: true,
url: 'prefer-required',
url: "prefer-required"
},
fixable: 'code',
fixable: "code"
},
create: createBannedAttributeRule({
preferred: 'toBeRequired',
negatedPreferred: 'not.toBeRequired',
attributes: ['required', 'aria-required'],
}),
preferred: "toBeRequired",
negatedPreferred: "not.toBeRequired",
attributes: ["required", "aria-required"]
})
};

@@ -5,3 +5,3 @@ /**

*/
'use strict';
"use strict";

@@ -16,6 +16,6 @@ //------------------------------------------------------------------------------

description:
'prefer toHaveAttribute over checking getAttribute/hasAttribute ',
recommended: true,
"prefer toHaveAttribute over checking getAttribute/hasAttribute ",
recommended: true
},
fixable: 'code',
fixable: "code"
},

@@ -37,8 +37,8 @@

node.parent.parent.property.range[0],
node.parent.parent.parent.range[1],
node.parent.parent.parent.range[1]
],
`not.toHaveAttribute(${node.arguments[0].raw})`
),
)
];
},
}
});

@@ -55,3 +55,3 @@ },

fixer.removeRange([node.callee.object.range[1], node.range[1]]),
fixer.replaceText(node.parent.parent.property, 'toHaveAttribute'),
fixer.replaceText(node.parent.parent.property, "toHaveAttribute"),
fixer.replaceText(

@@ -64,5 +64,5 @@ node.parent.parent.parent.arguments[0],

)}ing(${node.parent.parent.parent.arguments[0].raw})`
),
)
];
},
}
});

@@ -75,3 +75,3 @@ },

const isNullOrEmpty =
arg.length > 0 && (arg[0].value === null || arg[0].value === '');
arg.length > 0 && (arg[0].value === null || arg[0].value === "");

@@ -98,7 +98,7 @@ context.report({

node.parent.parent.property,
`${isNullOrEmpty ? 'not.' : ''}toHaveAttribute`
`${isNullOrEmpty ? "not." : ""}toHaveAttribute`
),
lastFixer,
lastFixer
];
},
}
});

@@ -111,3 +111,3 @@ },

node: node.parent.parent.property,
message: 'Invalid matcher for hasAttribute',
message: "Invalid matcher for hasAttribute"
});

@@ -120,3 +120,3 @@ },

node: node.parent.parent.property,
message: 'Invalid matcher for getAttribute',
message: "Invalid matcher for getAttribute"
});

@@ -127,3 +127,3 @@ },

) {
if (typeof node.parent.parent.parent.arguments[0].value === 'boolean') {
if (typeof node.parent.parent.parent.arguments[0].value === "boolean") {
context.report({

@@ -139,4 +139,4 @@ node: node.parent,

node.parent.parent.parent.arguments[0].value === false
? 'not.'
: ''
? "not."
: ""
}toHaveAttribute`

@@ -147,5 +147,5 @@ ),

node.arguments[0].raw
),
)
];
},
}
});

@@ -155,3 +155,3 @@ } else {

node: node.parent.parent.property,
message: 'Invalid matcher for hasAttribute',
message: "Invalid matcher for hasAttribute"
});

@@ -172,14 +172,14 @@ }

node.parent.parent.property.range[0],
node.parent.parent.parent.range[1],
node.parent.parent.parent.range[1]
],
`${
node.parent.parent.property.name === 'toBeFalsy' ? 'not.' : ''
node.parent.parent.property.name === "toBeFalsy" ? "not." : ""
}toHaveAttribute(${node.arguments[0].raw})`
),
)
];
},
}
});
},
}
};
},
}
};
{
"name": "eslint-plugin-jest-dom",
"version": "2.0.1",
"version": "2.1.0",
"description": "lint rules for use with jest-dom",

@@ -15,2 +15,3 @@ "keywords": [

"test": "jest",
"format": "prettier \"**/*.js\" --write",
"generate-readme-table": "node build/generate-readme-table.js"

@@ -17,0 +18,0 @@ },

@@ -77,2 +77,3 @@ # eslint-plugin-jest-dom

[prefer-to-have-attribute](https://github.com/testing-library/eslint-plugin-jest-dom/blob/master/docs/rules/prefer-to-have-attribute.md) | ✔️ | 🛠 | prefer toHaveAttribute over checking getAttribute/hasAttribute
[prefer-to-have-text-content](https://github.com/testing-library/eslint-plugin-jest-dom/blob/master/docs/rules/prefer-to-have-text-content.md) | ✔️ | 🛠 | Prefer toHaveTextContent over checking element.textContent
<!-- __END AUTOGENERATED TABLE__ -->

@@ -79,0 +80,0 @@

module.exports = ({ preferred, negatedPreferred, attribute }) => {
let doubleNegativeCases = [];
if (negatedPreferred.startsWith('toBe')) {
if (negatedPreferred.startsWith("toBe")) {
doubleNegativeCases = [

@@ -9,6 +9,6 @@ {

{
message: `Use ${preferred} instead of not.${negatedPreferred}`,
},
message: `Use ${preferred} instead of not.${negatedPreferred}`
}
],
output: `expect(element).${preferred}`,
output: `expect(element).${preferred}`
},

@@ -19,7 +19,7 @@ {

{
message: `Use ${negatedPreferred} instead of not.${preferred}`,
},
message: `Use ${negatedPreferred} instead of not.${preferred}`
}
],
output: `expect(element).${negatedPreferred}`,
},
output: `expect(element).${negatedPreferred}`
}
];

@@ -34,6 +34,6 @@ }

{
message: `Use ${preferred} instead of checking .${attribute} directly`,
},
message: `Use ${preferred} instead of checking .${attribute} directly`
}
],
output: `expect(getByText('foo')).${[preferred]}`,
output: `expect(getByText('foo')).${[preferred]}`
},

@@ -44,6 +44,6 @@ {

{
message: `Use ${negatedPreferred} instead of checking .${attribute} directly`,
},
message: `Use ${negatedPreferred} instead of checking .${attribute} directly`
}
],
output: `expect(getByText('foo')).${[negatedPreferred]}`,
output: `expect(getByText('foo')).${[negatedPreferred]}`
},

@@ -54,7 +54,7 @@ {

{
message: `Use ${preferred} instead of checking .${attribute} directly`,
},
message: `Use ${preferred} instead of checking .${attribute} directly`
}
],
output: `expect(getByText('foo')).${[preferred]}`,
},
output: `expect(getByText('foo')).${[preferred]}`
}
];

@@ -67,3 +67,3 @@ }

`expect(element).${negatedPreferred}`,
`expect(element).toHaveProperty('value', 'bar')`,
`expect(element).toHaveProperty('value', 'bar')`
],

@@ -77,6 +77,6 @@ invalid: [

{
message: `Use ${preferred} instead of toHaveProperty('${attribute}', true)`,
},
message: `Use ${preferred} instead of toHaveProperty('${attribute}', true)`
}
],
output: `expect(element).${preferred}`,
output: `expect(element).${preferred}`
},

@@ -87,6 +87,6 @@ {

{
message: `Use ${negatedPreferred} instead of toHaveProperty('${attribute}', false)`,
},
message: `Use ${negatedPreferred} instead of toHaveProperty('${attribute}', false)`
}
],
output: `expect(element).${negatedPreferred}`,
output: `expect(element).${negatedPreferred}`
},

@@ -97,6 +97,6 @@ {

{
message: `Use ${negatedPreferred} instead of toHaveAttribute('${attribute}', false)`,
},
message: `Use ${negatedPreferred} instead of toHaveAttribute('${attribute}', false)`
}
],
output: `expect(element).${negatedPreferred}`,
output: `expect(element).${negatedPreferred}`
},

@@ -107,6 +107,6 @@ {

{
message: `Use ${preferred} instead of toHaveProperty('${attribute}')`,
},
message: `Use ${preferred} instead of toHaveProperty('${attribute}')`
}
],
output: `expect(element).${preferred}`,
output: `expect(element).${preferred}`
},

@@ -117,6 +117,6 @@ {

{
message: `Use ${preferred} instead of toHaveAttribute('${attribute}')`,
},
message: `Use ${preferred} instead of toHaveAttribute('${attribute}')`
}
],
output: `expect(element).${preferred}`,
output: `expect(element).${preferred}`
},

@@ -127,6 +127,6 @@ {

{
message: `Use ${negatedPreferred} instead of not.toHaveAttribute('${attribute}')`,
},
message: `Use ${negatedPreferred} instead of not.toHaveAttribute('${attribute}')`
}
],
output: `expect(element).${negatedPreferred}`,
output: `expect(element).${negatedPreferred}`
},

@@ -137,6 +137,6 @@ {

{
message: `Use ${negatedPreferred} instead of not.toHaveProperty('${attribute}')`,
},
message: `Use ${negatedPreferred} instead of not.toHaveProperty('${attribute}')`
}
],
output: `expect(element).${negatedPreferred}`,
output: `expect(element).${negatedPreferred}`
},

@@ -147,6 +147,6 @@ {

{
message: `Use ${preferred} instead of toHaveAttribute("${attribute}", "")`,
},
message: `Use ${preferred} instead of toHaveAttribute("${attribute}", "")`
}
],
output: `expect(element).${preferred}`,
output: `expect(element).${preferred}`
},

@@ -157,6 +157,6 @@ {

{
message: `Use ${preferred} instead of toHaveAttribute("${attribute}", "")`,
},
message: `Use ${preferred} instead of toHaveAttribute("${attribute}", "")`
}
],
output: `expect(getByText("foo")).${preferred}`,
output: `expect(getByText("foo")).${preferred}`
},

@@ -167,9 +167,9 @@ {

{
message: `Use ${negatedPreferred} instead of not.toHaveProperty('${attribute}')`,
},
message: `Use ${negatedPreferred} instead of not.toHaveProperty('${attribute}')`
}
],
output: `expect(getByText("foo")).${negatedPreferred}`,
},
],
output: `expect(getByText("foo")).${negatedPreferred}`
}
]
};
};

@@ -1,14 +0,14 @@

const { rules, generateRecommendedConfig, configs } = require('../lib/index');
const { rules, generateRecommendedConfig, configs } = require("../lib/index");
it('should have all the rules', () => {
it("should have all the rules", () => {
expect(rules).toMatchSnapshot();
});
it('should have a recommended config with recommended rules', () => {
it("should have a recommended config with recommended rules", () => {
expect(
generateRecommendedConfig({
good: { meta: { docs: { recommended: true } } },
bad: { meta: { docs: { recommended: false } } },
bad: { meta: { docs: { recommended: false } } }
})
).toEqual({ 'jest-dom/good': 'error' });
).toEqual({ "jest-dom/good": "error" });
});

@@ -5,24 +5,24 @@ /**

*/
'use strict';
const createBannedAttributeTestCases = require('../../fixtures/createBannedAttributeTestCases');
"use strict";
const createBannedAttributeTestCases = require("../../fixtures/createBannedAttributeTestCases");
const bannedAttributes = [
{
preferred: 'toBeDisabled()',
negatedPreferred: 'toBeEnabled()',
attributes: ['disabled'],
ruleName: 'prefer-enabled-disabled',
preferred: "toBeDisabled()",
negatedPreferred: "toBeEnabled()",
attributes: ["disabled"],
ruleName: "prefer-enabled-disabled"
},
{
preferred: 'toBeRequired()',
negatedPreferred: 'not.toBeRequired()',
attributes: ['required', 'aria-required'],
ruleName: 'prefer-required',
preferred: "toBeRequired()",
negatedPreferred: "not.toBeRequired()",
attributes: ["required", "aria-required"],
ruleName: "prefer-required"
},
{
preferred: 'toBeChecked()',
negatedPreferred: 'not.toBeChecked()',
attributes: ['checked', 'aria-checked'],
ruleName: 'prefer-checked',
},
preferred: "toBeChecked()",
negatedPreferred: "not.toBeChecked()",
attributes: ["checked", "aria-checked"],
ruleName: "prefer-checked"
}
];

@@ -33,3 +33,3 @@

const rule = require(`../../../lib/rules/${ruleName}`);
const RuleTester = require('eslint').RuleTester;
const RuleTester = require("eslint").RuleTester;

@@ -40,3 +40,3 @@ // const preferred = 'toBeDisabled()';

const ruleTester = new RuleTester({
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
parserOptions: { ecmaVersion: 2015, sourceType: "module" }
});

@@ -50,3 +50,3 @@ attributes.forEach(attribute => {

negatedPreferred,
attribute,
attribute
})

@@ -53,0 +53,0 @@ );

@@ -5,3 +5,3 @@ /**

*/
'use strict';
"use strict";

@@ -12,4 +12,4 @@ //------------------------------------------------------------------------------

let rule = require('../../../lib/rules/prefer-empty'),
RuleTester = require('eslint').RuleTester;
let rule = require("../../../lib/rules/prefer-empty"),
RuleTester = require("eslint").RuleTester;

@@ -21,3 +21,3 @@ //------------------------------------------------------------------------------

let ruleTester = new RuleTester();
ruleTester.run('prefer-empty', rule, {
ruleTester.run("prefer-empty", rule, {
valid: [

@@ -33,3 +33,3 @@ `expect(element.innerHTML).toBe('foo')`,

`expect(element.innerHTML === 'foo').toBe(true)`,
`expect(element.innerHTML !== 'foo').toBe(true)`,
`expect(element.innerHTML !== 'foo').toBe(true)`
],

@@ -42,6 +42,6 @@

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).toBeEmpty()`,
output: `expect(element).toBeEmpty()`
},

@@ -52,6 +52,6 @@ {

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).not.toBeEmpty()`,
output: `expect(element).not.toBeEmpty()`
},

@@ -62,6 +62,6 @@ {

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).not.toBeEmpty()`,
output: `expect(element).not.toBeEmpty()`
},

@@ -72,6 +72,6 @@ {

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).toBeEmpty()`,
output: `expect(element).toBeEmpty()`
},

@@ -82,6 +82,6 @@ {

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).toBeEmpty()`,
output: `expect(element).toBeEmpty()`
},

@@ -92,6 +92,6 @@ {

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).toBeEmpty()`,
output: `expect(element).toBeEmpty()`
},

@@ -102,6 +102,6 @@ {

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).not.toBeEmpty()`,
output: `expect(element).not.toBeEmpty()`
},

@@ -112,6 +112,6 @@ {

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).toBeEmpty()`,
output: `expect(element).toBeEmpty()`
},

@@ -123,6 +123,6 @@

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).toBeEmpty()`,
output: `expect(element).toBeEmpty()`
},

@@ -133,6 +133,6 @@ {

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).not.toBeEmpty()`,
output: `expect(element).not.toBeEmpty()`
},

@@ -144,6 +144,6 @@

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).not.toBeEmpty()`,
output: `expect(element).not.toBeEmpty()`
},

@@ -155,6 +155,6 @@

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).toBeEmpty()`,
output: `expect(element).toBeEmpty()`
},

@@ -165,6 +165,6 @@ {

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).toBeEmpty()`,
output: `expect(element).toBeEmpty()`
},

@@ -175,6 +175,6 @@ {

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).not.toBeEmpty()`,
output: `expect(element).not.toBeEmpty()`
},

@@ -186,6 +186,6 @@

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(element).not.toBeEmpty()`,
output: `expect(element).not.toBeEmpty()`
},

@@ -196,6 +196,6 @@ {

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(getByText('foo')).toBeEmpty()`,
output: `expect(getByText('foo')).toBeEmpty()`
},

@@ -207,6 +207,6 @@

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(getByText('foo')).toBeEmpty()`,
output: `expect(getByText('foo')).toBeEmpty()`
},

@@ -218,6 +218,6 @@

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(getByText('foo')).toBeEmpty()`,
output: `expect(getByText('foo')).toBeEmpty()`
},

@@ -229,6 +229,6 @@

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(getByText('foo')).toBeEmpty()`,
output: `expect(getByText('foo')).toBeEmpty()`
},

@@ -239,8 +239,8 @@ {

{
message: 'Use toBeEmpty instead of checking inner html.',
},
message: "Use toBeEmpty instead of checking inner html."
}
],
output: `expect(getByText('foo')).not.toBeEmpty()`,
},
],
output: `expect(getByText('foo')).not.toBeEmpty()`
}
]
});

@@ -5,12 +5,12 @@ /**

*/
'use strict';
"use strict";
let rule = require('../../../lib/rules/prefer-focus'),
RuleTester = require('eslint').RuleTester;
let rule = require("../../../lib/rules/prefer-focus"),
RuleTester = require("eslint").RuleTester;
let ruleTester = new RuleTester();
ruleTester.run('prefer-focus', rule, {
ruleTester.run("prefer-focus", rule, {
valid: [
`expect(document.activeElement).toBeNull()`,
`expect(document.activeElement).not.toBeNull()`,
`expect(document.activeElement).not.toBeNull()`
],

@@ -20,9 +20,9 @@

{
code: 'expect(document.activeElement).toBe(foo)',
code: "expect(document.activeElement).toBe(foo)",
errors: [
{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: 'expect(foo).toHaveFocus()',
output: "expect(foo).toHaveFocus()"
},

@@ -33,6 +33,6 @@ {

{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: `expect(getByText('Foo')).toHaveFocus()`,
output: `expect(getByText('Foo')).toHaveFocus()`
},

@@ -43,100 +43,100 @@ {

{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: `expect(getByText('Foo')).not.toHaveFocus()`,
output: `expect(getByText('Foo')).not.toHaveFocus()`
},
{
code: 'expect(document.activeElement).not.toBe(foo)',
code: "expect(document.activeElement).not.toBe(foo)",
errors: [
{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: 'expect(foo).not.toHaveFocus()',
output: "expect(foo).not.toHaveFocus()"
},
{
code: 'expect(foo).not.toBe(document.activeElement)',
code: "expect(foo).not.toBe(document.activeElement)",
errors: [
{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: 'expect(foo).not.toHaveFocus()',
output: "expect(foo).not.toHaveFocus()"
},
{
code: 'expect(window.document.activeElement).toBe(foo)',
code: "expect(window.document.activeElement).toBe(foo)",
errors: [
{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: 'expect(foo).toHaveFocus()',
output: "expect(foo).toHaveFocus()"
},
{
code: 'expect(global.window.document.activeElement).toBe(foo)',
code: "expect(global.window.document.activeElement).toBe(foo)",
errors: [
{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: 'expect(foo).toHaveFocus()',
output: "expect(foo).toHaveFocus()"
},
{
code: 'expect(global.document.activeElement).toBe(foo)',
code: "expect(global.document.activeElement).toBe(foo)",
errors: [
{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: 'expect(foo).toHaveFocus()',
output: "expect(foo).toHaveFocus()"
},
{
code: 'expect(foo).toBe(global.document.activeElement)',
code: "expect(foo).toBe(global.document.activeElement)",
errors: [
{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: 'expect(foo).toHaveFocus()',
output: "expect(foo).toHaveFocus()"
},
{
code: 'expect(foo).toBe(window.document.activeElement)',
code: "expect(foo).toBe(window.document.activeElement)",
errors: [
{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: 'expect(foo).toHaveFocus()',
output: "expect(foo).toHaveFocus()"
},
{
code: 'expect(foo).toBe(global.window.document.activeElement)',
code: "expect(foo).toBe(global.window.document.activeElement)",
errors: [
{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: 'expect(foo).toHaveFocus()',
output: "expect(foo).toHaveFocus()"
},
{
code: 'expect(foo).toBe(document.activeElement)',
code: "expect(foo).toBe(document.activeElement)",
errors: [
{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: 'expect(foo).toHaveFocus()',
output: "expect(foo).toHaveFocus()"
},
{
code: 'expect(foo).toEqual(document.activeElement)',
code: "expect(foo).toEqual(document.activeElement)",
errors: [
{
message: 'Use toHaveFocus instead of checking activeElement',
},
message: "Use toHaveFocus instead of checking activeElement"
}
],
output: 'expect(foo).toHaveFocus()',
},
],
output: "expect(foo).toHaveFocus()"
}
]
});

@@ -5,3 +5,3 @@ /**

*/
'use strict';
"use strict";

@@ -12,4 +12,4 @@ //------------------------------------------------------------------------------

let rule = require('../../../lib/rules/prefer-to-have-attribute'),
RuleTester = require('eslint').RuleTester;
let rule = require("../../../lib/rules/prefer-to-have-attribute"),
RuleTester = require("eslint").RuleTester;

@@ -21,8 +21,8 @@ //------------------------------------------------------------------------------

let ruleTester = new RuleTester();
ruleTester.run('prefer-to-have-attribute', rule, {
ruleTester.run("prefer-to-have-attribute", rule, {
valid: [
'expect(element.foo).toBeTruthy()',
'expect(element.getAttributeNode()).toBeNull()',
"expect(element.foo).toBeTruthy()",
"expect(element.getAttributeNode()).toBeNull()",
`expect(element.getAttribute('foo')).toBeGreaterThan(2)`,
`expect(element.getAttribute('foo')).toBeLessThan(2)`,
`expect(element.getAttribute('foo')).toBeLessThan(2)`
],

@@ -35,6 +35,6 @@

{
message: 'Use toHaveAttribute instead of asserting on getAttribute',
},
message: "Use toHaveAttribute instead of asserting on getAttribute"
}
],
output: `expect(element).toHaveAttribute('foo', expect.stringMatching(/bar/));`,
output: `expect(element).toHaveAttribute('foo', expect.stringMatching(/bar/));`
},

@@ -45,6 +45,6 @@ {

{
message: 'Use toHaveAttribute instead of asserting on getAttribute',
},
message: "Use toHaveAttribute instead of asserting on getAttribute"
}
],
output: `expect(element).toHaveAttribute('foo', expect.stringContaining('bar'));`,
output: `expect(element).toHaveAttribute('foo', expect.stringContaining('bar'));`
},

@@ -55,6 +55,6 @@ {

{
message: 'Use toHaveAttribute instead of asserting on getAttribute',
},
message: "Use toHaveAttribute instead of asserting on getAttribute"
}
],
output: 'expect(element).toHaveAttribute("foo", "bar")',
output: 'expect(element).toHaveAttribute("foo", "bar")'
},

@@ -65,6 +65,6 @@ {

{
message: 'Use toHaveAttribute instead of asserting on getAttribute',
},
message: "Use toHaveAttribute instead of asserting on getAttribute"
}
],
output: `expect(getByText("yes")).toHaveAttribute("data-blah", expect.stringMatching(/foo/))`,
output: `expect(getByText("yes")).toHaveAttribute("data-blah", expect.stringMatching(/foo/))`
},

@@ -75,6 +75,6 @@ {

{
message: 'Invalid matcher for hasAttribute',
},
message: "Invalid matcher for hasAttribute"
}
],
output: null,
output: null
},

@@ -85,6 +85,6 @@ {

{
message: 'Invalid matcher for hasAttribute',
},
message: "Invalid matcher for hasAttribute"
}
],
output: null,
output: null
},

@@ -95,6 +95,6 @@ {

{
message: 'Invalid matcher for getAttribute',
},
message: "Invalid matcher for getAttribute"
}
],
output: null,
output: null
},

@@ -105,6 +105,6 @@ {

{
message: 'Invalid matcher for getAttribute',
},
message: "Invalid matcher for getAttribute"
}
],
output: null,
output: null
},

@@ -115,6 +115,6 @@ {

{
message: 'Invalid matcher for hasAttribute',
},
message: "Invalid matcher for hasAttribute"
}
],
output: null,
output: null
},

@@ -125,6 +125,6 @@ {

{
message: 'Use toHaveAttribute instead of asserting on hasAttribute',
},
message: "Use toHaveAttribute instead of asserting on hasAttribute"
}
],
output: 'expect(element).toHaveAttribute("foo")',
output: 'expect(element).toHaveAttribute("foo")'
},

@@ -135,6 +135,6 @@ {

{
message: 'Use toHaveAttribute instead of asserting on hasAttribute',
},
message: "Use toHaveAttribute instead of asserting on hasAttribute"
}
],
output: 'expect(element).not.toHaveAttribute("foo")',
output: 'expect(element).not.toHaveAttribute("foo")'
},

@@ -145,6 +145,6 @@ {

{
message: 'Use toHaveAttribute instead of asserting on hasAttribute',
},
message: "Use toHaveAttribute instead of asserting on hasAttribute"
}
],
output: 'expect(element).toHaveAttribute("foo")',
output: 'expect(element).toHaveAttribute("foo")'
},

@@ -155,6 +155,6 @@ {

{
message: 'Use toHaveAttribute instead of asserting on hasAttribute',
},
message: "Use toHaveAttribute instead of asserting on hasAttribute"
}
],
output: 'expect(element).not.toHaveAttribute("foo")',
output: 'expect(element).not.toHaveAttribute("foo")'
},

@@ -165,6 +165,6 @@ {

{
message: 'Use toHaveAttribute instead of asserting on hasAttribute',
},
message: "Use toHaveAttribute instead of asserting on hasAttribute"
}
],
output: 'expect(element).not.toHaveAttribute("foo")',
output: 'expect(element).not.toHaveAttribute("foo")'
},

@@ -175,6 +175,6 @@ {

{
message: 'Use toHaveAttribute instead of asserting on getAttribute',
},
message: "Use toHaveAttribute instead of asserting on getAttribute"
}
],
output: 'expect(element).toHaveAttribute("foo", "bar")',
output: 'expect(element).toHaveAttribute("foo", "bar")'
},

@@ -185,6 +185,6 @@ {

{
message: 'Use toHaveAttribute instead of asserting on getAttribute',
},
message: "Use toHaveAttribute instead of asserting on getAttribute"
}
],
output: 'expect(element).toHaveAttribute("foo", "bar")',
output: 'expect(element).toHaveAttribute("foo", "bar")'
},

@@ -195,6 +195,6 @@ {

{
message: 'Use toHaveAttribute instead of asserting on getAttribute',
},
message: "Use toHaveAttribute instead of asserting on getAttribute"
}
],
output: 'expect(element).not.toHaveAttribute("foo")',
output: 'expect(element).not.toHaveAttribute("foo")'
},

@@ -205,8 +205,8 @@ {

{
message: 'Use toHaveAttribute instead of asserting on getAttribute',
},
message: "Use toHaveAttribute instead of asserting on getAttribute"
}
],
output: 'expect(element).not.toHaveAttribute("foo")',
},
],
output: 'expect(element).not.toHaveAttribute("foo")'
}
]
});

Sorry, the diff of this file is not supported yet

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