-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathexpect-expect.test.ts
123 lines (122 loc) · 3.68 KB
/
expect-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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import rule from '../../src/rules/expect-expect.js'
import { javascript, runRuleTester } from '../utils/rule-tester.js'
runRuleTester('expect-expect', rule, {
invalid: [
{
code: 'test("should fail", () => {});',
errors: [{ messageId: 'noAssertions', type: 'Identifier' }],
},
{
code: 'test.skip("should fail", () => {});',
errors: [{ messageId: 'noAssertions', type: 'MemberExpression' }],
},
{
code: javascript`
test('should fail', async ({ page }) => {
await assertCustomCondition(page)
})
`,
errors: [{ messageId: 'noAssertions', type: 'Identifier' }],
},
{
code: javascript`
test('should fail', async ({ page }) => {
await assertCustomCondition(page)
})
`,
errors: [{ messageId: 'noAssertions', type: 'Identifier' }],
name: 'Custom assert function',
options: [{ assertFunctionNames: ['wayComplexCustomCondition'] }],
},
{
code: 'it("should pass", () => hi(true).toBeDefined())',
errors: [{ messageId: 'noAssertions', type: 'Identifier' }],
name: 'Global aliases',
settings: {
playwright: {
globalAliases: { test: ['it'] },
},
},
},
],
valid: [
'foo();',
'["bar"]();',
'testing("will test something eventually", () => {})',
'test("should pass", () => expect(true).toBeDefined())',
'test("should pass", () => test.expect(true).toBeDefined())',
'test.slow("should pass", () => expect(true).toBeDefined())',
'test.skip("should pass", () => expect(true).toBeDefined())',
// Config methods
'test.describe.configure({ mode: "parallel" })',
'test.info()',
'test.use({ locale: "en-US" })',
// test.skip
'test.skip();',
'test.skip(true);',
'test.skip(browserName === "Chrome", "This feature is skipped on Chrome")',
'test.skip(({ browserName }) => browserName === "Chrome");',
'test.skip("foo", () => { expect(true).toBeDefined(); })',
// test.slow
'test.slow();',
'test.slow(true);',
'test.slow(browserName === "webkit", "This feature is slow on Mac")',
'test.slow(({ browserName }) => browserName === "Chrome");',
'test.slow("foo", () => { expect(true).toBeDefined(); })',
// test.step
{
code: javascript`
test('steps', async ({ page }) => {
await test.step('first tab', async () => {
await expect(page.getByText('Hello')).toBeVisible();
});
});
`,
},
{
code: javascript`
test.only('steps', async ({ page }) => {
await test.step('first tab', async () => {
await expect(page.getByText('Hello')).toBeVisible();
});
});
`,
},
{
code: javascript`
test('should fail', async ({ page }) => {
await assertCustomCondition(page)
})
`,
name: 'Custom assert function',
options: [{ assertFunctionNames: ['assertCustomCondition'] }],
},
{
code: javascript`
test('should fail', async ({ myPage, page }) => {
await myPage.assertCustomCondition(page)
})
`,
name: 'Custom assert class method',
options: [{ assertFunctionNames: ['assertCustomCondition'] }],
},
{
code: 'it("should pass", () => expect(true).toBeDefined())',
name: 'Global alias - test',
settings: {
playwright: {
globalAliases: { test: ['it'] },
},
},
},
{
code: 'test("should pass", () => assert(true).toBeDefined())',
name: 'Global alias - assert',
settings: {
playwright: {
globalAliases: { expect: ['assert'] },
},
},
},
],
})