/
no-standalone-expect-test.ts
77 lines (75 loc) · 2.82 KB
/
no-standalone-expect-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { TSESLint } from '@typescript-eslint/experimental-utils';
import rule from '../no-standalone-expect';
const ruleTester = new TSESLint.RuleTester({
parserOptions: {
ecmaVersion: 2015,
},
});
ruleTester.run('no-standalone-expect', rule, {
valid: [
'describe("a test", () => { it("an it", () => {expect(1).toBe(1); }); });',
'describe("a test", () => { it("an it", () => { const func = () => { expect(1).toBe(1); }; }); });',
'describe("a test", () => { const func = () => { expect(1).toBe(1); }; });',
'describe("a test", () => { function func() { expect(1).toBe(1); }; });',
'describe("a test", () => { const func = function(){ expect(1).toBe(1); }; });',
'it("an it", () => expect(1).toBe(1))',
'const func = function(){ expect(1).toBe(1); };',
'const func = () => expect(1).toBe(1);',
'expect.hasAssertions()',
'{}',
'it.each([1, true])("trues", value => { expect(value).toBe(true); });',
'it.each([1, true])("trues", value => { expect(value).toBe(true); }); it("an it", () => { expect(1).toBe(1) });',
`
it.each\`
num | value
\${1} | \${true}
\`('trues', ({ value }) => {
expect(value).toBe(true);
});
`,
'it.only("an only", value => { expect(value).toBe(true); });',
'describe.each([1, true])("trues", value => { it("an it", () => expect(value).toBe(true) ); });',
],
invalid: [
{
code: 'describe("a test", () => { expect(1).toBe(1); });',
errors: [{ endColumn: 37, column: 28, messageId: 'unexpectedExpect' }],
},
{
code: 'describe("a test", () => expect(1).toBe(1));',
errors: [{ endColumn: 35, column: 26, messageId: 'unexpectedExpect' }],
},
{
code:
'describe("a test", () => { const func = () => { expect(1).toBe(1); }; expect(1).toBe(1); });',
errors: [{ endColumn: 80, column: 71, messageId: 'unexpectedExpect' }],
},
{
code:
'describe("a test", () => { it(() => { expect(1).toBe(1); }); expect(1).toBe(1); });',
errors: [{ endColumn: 72, column: 63, messageId: 'unexpectedExpect' }],
},
{
code: 'expect(1).toBe(1);',
errors: [{ endColumn: 10, column: 1, messageId: 'unexpectedExpect' }],
},
{
code: 'expect(1).toBe',
errors: [{ endColumn: 10, column: 1, messageId: 'unexpectedExpect' }],
},
{
code: '{expect(1).toBe(1)}',
errors: [{ endColumn: 11, column: 2, messageId: 'unexpectedExpect' }],
},
{
code:
'it.each([1, true])("trues", value => { expect(value).toBe(true); }); expect(1).toBe(1);',
errors: [{ endColumn: 79, column: 70, messageId: 'unexpectedExpect' }],
},
{
code:
'describe.each([1, true])("trues", value => { expect(value).toBe(true); });',
errors: [{ endColumn: 59, column: 46, messageId: 'unexpectedExpect' }],
},
],
});