Skip to content

Commit b14a445

Browse files
test: add extra tests (#332)
1 parent 0983664 commit b14a445

File tree

2 files changed

+138
-103
lines changed

2 files changed

+138
-103
lines changed
+75-82
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,87 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`should export proper "angular" config 1`] = `
3+
exports[`should export configs that refer to actual rules 1`] = `
44
Object {
5-
"plugins": Array [
6-
"testing-library",
7-
],
8-
"rules": Object {
9-
"testing-library/await-async-query": "error",
10-
"testing-library/await-async-utils": "error",
11-
"testing-library/no-await-sync-query": "error",
12-
"testing-library/no-container": "error",
13-
"testing-library/no-debug": "error",
14-
"testing-library/no-dom-import": Array [
15-
"error",
16-
"angular",
5+
"angular": Object {
6+
"plugins": Array [
7+
"testing-library",
178
],
18-
"testing-library/no-node-access": "error",
19-
"testing-library/no-promise-in-fire-event": "error",
20-
"testing-library/no-wait-for-empty-callback": "error",
21-
"testing-library/prefer-find-by": "error",
22-
"testing-library/prefer-screen-queries": "error",
23-
"testing-library/render-result-naming-convention": "error",
9+
"rules": Object {
10+
"testing-library/await-async-query": "error",
11+
"testing-library/await-async-utils": "error",
12+
"testing-library/no-await-sync-query": "error",
13+
"testing-library/no-container": "error",
14+
"testing-library/no-debug": "error",
15+
"testing-library/no-dom-import": Array [
16+
"error",
17+
"angular",
18+
],
19+
"testing-library/no-node-access": "error",
20+
"testing-library/no-promise-in-fire-event": "error",
21+
"testing-library/no-wait-for-empty-callback": "error",
22+
"testing-library/prefer-find-by": "error",
23+
"testing-library/prefer-screen-queries": "error",
24+
"testing-library/render-result-naming-convention": "error",
25+
},
2426
},
25-
}
26-
`;
27-
28-
exports[`should export proper "dom" config 1`] = `
29-
Object {
30-
"plugins": Array [
31-
"testing-library",
32-
],
33-
"rules": Object {
34-
"testing-library/await-async-query": "error",
35-
"testing-library/await-async-utils": "error",
36-
"testing-library/no-await-sync-query": "error",
37-
"testing-library/no-promise-in-fire-event": "error",
38-
"testing-library/no-wait-for-empty-callback": "error",
39-
"testing-library/prefer-find-by": "error",
40-
"testing-library/prefer-screen-queries": "error",
27+
"dom": Object {
28+
"plugins": Array [
29+
"testing-library",
30+
],
31+
"rules": Object {
32+
"testing-library/await-async-query": "error",
33+
"testing-library/await-async-utils": "error",
34+
"testing-library/no-await-sync-query": "error",
35+
"testing-library/no-promise-in-fire-event": "error",
36+
"testing-library/no-wait-for-empty-callback": "error",
37+
"testing-library/prefer-find-by": "error",
38+
"testing-library/prefer-screen-queries": "error",
39+
},
4140
},
42-
}
43-
`;
44-
45-
exports[`should export proper "react" config 1`] = `
46-
Object {
47-
"plugins": Array [
48-
"testing-library",
49-
],
50-
"rules": Object {
51-
"testing-library/await-async-query": "error",
52-
"testing-library/await-async-utils": "error",
53-
"testing-library/no-await-sync-query": "error",
54-
"testing-library/no-container": "error",
55-
"testing-library/no-debug": "error",
56-
"testing-library/no-dom-import": Array [
57-
"error",
58-
"react",
41+
"react": Object {
42+
"plugins": Array [
43+
"testing-library",
5944
],
60-
"testing-library/no-node-access": "error",
61-
"testing-library/no-promise-in-fire-event": "error",
62-
"testing-library/no-wait-for-empty-callback": "error",
63-
"testing-library/prefer-find-by": "error",
64-
"testing-library/prefer-screen-queries": "error",
65-
"testing-library/render-result-naming-convention": "error",
45+
"rules": Object {
46+
"testing-library/await-async-query": "error",
47+
"testing-library/await-async-utils": "error",
48+
"testing-library/no-await-sync-query": "error",
49+
"testing-library/no-container": "error",
50+
"testing-library/no-debug": "error",
51+
"testing-library/no-dom-import": Array [
52+
"error",
53+
"react",
54+
],
55+
"testing-library/no-node-access": "error",
56+
"testing-library/no-promise-in-fire-event": "error",
57+
"testing-library/no-wait-for-empty-callback": "error",
58+
"testing-library/prefer-find-by": "error",
59+
"testing-library/prefer-screen-queries": "error",
60+
"testing-library/render-result-naming-convention": "error",
61+
},
6662
},
67-
}
68-
`;
69-
70-
exports[`should export proper "vue" config 1`] = `
71-
Object {
72-
"plugins": Array [
73-
"testing-library",
74-
],
75-
"rules": Object {
76-
"testing-library/await-async-query": "error",
77-
"testing-library/await-async-utils": "error",
78-
"testing-library/await-fire-event": "error",
79-
"testing-library/no-await-sync-query": "error",
80-
"testing-library/no-container": "error",
81-
"testing-library/no-debug": "error",
82-
"testing-library/no-dom-import": Array [
83-
"error",
84-
"vue",
63+
"vue": Object {
64+
"plugins": Array [
65+
"testing-library",
8566
],
86-
"testing-library/no-node-access": "error",
87-
"testing-library/no-promise-in-fire-event": "error",
88-
"testing-library/no-wait-for-empty-callback": "error",
89-
"testing-library/prefer-find-by": "error",
90-
"testing-library/prefer-screen-queries": "error",
91-
"testing-library/render-result-naming-convention": "error",
67+
"rules": Object {
68+
"testing-library/await-async-query": "error",
69+
"testing-library/await-async-utils": "error",
70+
"testing-library/await-fire-event": "error",
71+
"testing-library/no-await-sync-query": "error",
72+
"testing-library/no-container": "error",
73+
"testing-library/no-debug": "error",
74+
"testing-library/no-dom-import": Array [
75+
"error",
76+
"vue",
77+
],
78+
"testing-library/no-node-access": "error",
79+
"testing-library/no-promise-in-fire-event": "error",
80+
"testing-library/no-wait-for-empty-callback": "error",
81+
"testing-library/prefer-find-by": "error",
82+
"testing-library/prefer-screen-queries": "error",
83+
"testing-library/render-result-naming-convention": "error",
84+
},
9285
},
9386
}
9487
`;

tests/index.test.ts

+63-21
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,67 @@
1-
// eslint-disable-next-line @typescript-eslint/no-var-requires
2-
const { configs, rules } = require('../lib');
3-
import * as fs from 'fs';
4-
import * as path from 'path';
5-
6-
const rulesModules = fs.readdirSync(path.join(__dirname, '../lib/rules'));
7-
8-
it('should export all available rules', () => {
9-
const availableRules = rulesModules.map((module) =>
10-
module.replace('.ts', '')
11-
);
12-
expect(Object.keys(rules)).toEqual(availableRules);
1+
import { existsSync } from 'fs';
2+
import { resolve } from 'path';
3+
4+
import plugin from '../lib';
5+
6+
const numberOfRules = 24;
7+
const ruleNames = Object.keys(plugin.rules);
8+
9+
// eslint-disable-next-line jest/expect-expect
10+
it('should have a corresponding doc for each rule', () => {
11+
ruleNames.forEach((rule) => {
12+
const docPath = resolve(__dirname, '../docs/rules', `${rule}.md`);
13+
14+
if (!existsSync(docPath)) {
15+
throw new Error(
16+
`Could not find documentation file for rule "${rule}" in path "${docPath}"`
17+
);
18+
}
19+
});
20+
});
21+
22+
// eslint-disable-next-line jest/expect-expect
23+
it('should have a corresponding test for each rule', () => {
24+
ruleNames.forEach((rule) => {
25+
const testPath = resolve(__dirname, './lib/rules/', `${rule}.test.ts`);
26+
27+
if (!existsSync(testPath)) {
28+
throw new Error(
29+
`Could not find test file for rule "${rule}" in path "${testPath}"`
30+
);
31+
}
32+
});
1333
});
1434

15-
it.each(['dom', 'angular', 'react', 'vue'])(
16-
'should export proper "%s" config',
17-
(configName) => {
18-
expect(configs[configName]).toMatchSnapshot();
35+
// eslint-disable-next-line jest/expect-expect
36+
it('should have the correct amount of rules', () => {
37+
const { length } = ruleNames;
1938

20-
// make sure all enabled rules start by "testing-library/" prefix
21-
Object.keys(configs[configName].rules).forEach((ruleEnabled) => {
22-
expect(ruleEnabled).toMatch(/^testing-library\/.+$/);
23-
});
39+
if (length !== numberOfRules) {
40+
throw new Error(
41+
`There should be exactly ${numberOfRules} rules, but there are ${length}. If you've added a new rule, please update this number.`
42+
);
2443
}
25-
);
44+
});
45+
46+
it('should export configs that refer to actual rules', () => {
47+
const allConfigs = plugin.configs;
48+
49+
expect(allConfigs).toMatchSnapshot();
50+
expect(Object.keys(allConfigs)).toEqual(['dom', 'angular', 'react', 'vue']);
51+
const allConfigRules = Object.values(allConfigs)
52+
.map((config) => Object.keys(config.rules))
53+
.reduce((previousValue, currentValue) => [
54+
...previousValue,
55+
...currentValue,
56+
]);
57+
58+
allConfigRules.forEach((rule) => {
59+
const ruleNamePrefix = 'testing-library/';
60+
const ruleName = rule.slice(ruleNamePrefix.length);
61+
62+
expect(rule.startsWith(ruleNamePrefix)).toBe(true);
63+
expect(ruleNames).toContain(ruleName);
64+
65+
expect(() => require(`../lib/rules/${ruleName}`)).not.toThrow();
66+
});
67+
});

0 commit comments

Comments
 (0)