-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathprefer-to-have-value.js
123 lines (110 loc) · 4.37 KB
/
prefer-to-have-value.js
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
/* eslint-disable no-template-curly-in-string */
/**
* @fileoverview Prefer toBeEmptyDOMElement over checking innerHTML
* @author Ben Monro
*/
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
import { FlatCompatRuleTester as RuleTester } from '../../rule-tester';
import * as rule from "../../../rules/prefer-to-have-value";
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2020 } });
const errors = [{ messageId: "use-to-have-value" }];
ruleTester.run("prefer-to-have-value", rule, {
valid: [
`expect().toBe(true)`,
`expect(screen.getByRole("radio").value).toEqual("foo")`,
`expect(screen.queryAllByRole("checkbox")[0].value).toStrictEqual("foo")`,
`async function x() { expect((await screen.findByRole("button")).value).toBe("foo") }`,
`expect(element).toHaveValue('foo')`,
`expect(element.value).toBeGreaterThan(2);`,
`expect(element.value).toBeLessThan(2);`,
`const element = document.getElementById('asdfasf');
expect(element.value).toEqual('foo');`,
`let element;
element = someOtherFunction();
expect(element.value).toStrictEqual('foo');`,
`const element = { value: 'foo' };
expect(element.value).toBe('foo');`,
`expect(screen.getByRole("radio").value).not.toEqual("foo")`,
`expect(screen.queryAllByRole("checkbox")[0].value).not.toStrictEqual("foo")`,
`async function x() { expect((await screen.findByRole("button")).value).not.toBe("foo") }`,
`const element = document.getElementById('asdfasf');
expect(element.value).not.toEqual('foo');`,
`let element;
element = someOtherFunction();
expect(element.value).not.toStrictEqual('foo');`,
`const element = { value: 'foo' };
expect(element.value).not.toBe('foo');`,
`
const res = makePath()();
expect(res.value).toEqual('/repositories/create');
`,
],
invalid: [
{
code: `expect(element).toHaveAttribute('value', 'foo')`,
errors,
output: `expect(element).toHaveValue('foo')`,
},
{
code: `expect(element).toHaveProperty("value", "foo")`,
errors,
output: `expect(element).toHaveValue("foo")`,
},
{
code: `expect(element).not.toHaveAttribute('value', 'foo')`,
errors,
output: `expect(element).not.toHaveValue('foo')`,
},
{
code: `expect(element).not.toHaveProperty("value", "foo")`,
errors,
output: `expect(element).not.toHaveValue("foo")`,
},
//==========================================================================
{
code: `expect(screen.getByRole("textbox").value).toEqual("foo")`,
errors,
output: `expect(screen.getByRole("textbox")).toHaveValue("foo")`,
},
{
code: `expect(screen.queryByRole("dropdown").value).toEqual("foo")`,
errors,
output: `expect(screen.queryByRole("dropdown")).toHaveValue("foo")`,
},
{
code: `async function x() { expect((await screen.findByRole("textbox")).value).toEqual("foo") }`,
errors,
output: `async function x() { expect((await screen.findByRole("textbox"))).toHaveValue("foo") }`,
},
{
code: `const element = screen.getByRole("textbox"); expect(element.value).toBe("foo");`,
errors,
output: `const element = screen.getByRole("textbox"); expect(element).toHaveValue("foo");`,
},
{
code: `expect(screen.getByRole("textbox").value).not.toEqual("foo")`,
errors,
output: `expect(screen.getByRole("textbox")).not.toHaveValue("foo")`,
},
{
code: `expect(screen.queryByRole("dropdown").value).not.toEqual("foo")`,
errors,
output: `expect(screen.queryByRole("dropdown")).not.toHaveValue("foo")`,
},
{
code: `async function x() { expect((await screen.getByRole("textbox")).value).not.toEqual("foo") }`,
errors,
output: `async function x() { expect((await screen.getByRole("textbox"))).not.toHaveValue("foo") }`,
},
{
code: `const element = screen.getByRole("textbox"); expect(element.value).not.toBe("foo");`,
errors,
output: `const element = screen.getByRole("textbox"); expect(element).not.toHaveValue("foo");`,
},
],
});