2
2
AST_NODE_TYPES ,
3
3
TSESLint ,
4
4
} from '@typescript-eslint/experimental-utils' ;
5
+ import dedent from 'dedent' ;
5
6
import resolveFrom from 'resolve-from' ;
6
7
import rule from '../expect-expect' ;
7
8
@@ -19,8 +20,12 @@ ruleTester.run('expect-expect', rule, {
19
20
'it("should pass", () => somePromise().then(() => expect(true).toBeDefined()))' ,
20
21
'it("should pass", myTest); function myTest() { expect(true).toBeDefined() }' ,
21
22
{
22
- code :
23
- 'test("should pass", () => { expect(true).toBeDefined(); foo(true).toBe(true); })' ,
23
+ code : dedent `
24
+ test('should pass', () => {
25
+ expect(true).toBeDefined();
26
+ foo(true).toBe(true);
27
+ });
28
+ ` ,
24
29
options : [ { assertFunctionNames : [ 'expect' , 'foo' ] } ] ,
25
30
} ,
26
31
{
@@ -32,23 +37,34 @@ ruleTester.run('expect-expect', rule, {
32
37
options : [ { assertFunctionNames : [ 'expect\\$' ] } ] ,
33
38
} ,
34
39
{
35
- code : ` test('verifies expect method call', () => new Foo().expect(123));` ,
40
+ code : " test('verifies expect method call', () => new Foo().expect(123));" ,
36
41
options : [ { assertFunctionNames : [ 'Foo.expect' ] } ] ,
37
42
} ,
38
43
{
39
- code : `test('verifies deep expect method call', () => tester.foo().expect(123));` ,
44
+ code : dedent `
45
+ test('verifies deep expect method call', () => {
46
+ tester.foo().expect(123);
47
+ });
48
+ ` ,
40
49
options : [ { assertFunctionNames : [ 'tester.foo.expect' ] } ] ,
41
50
} ,
42
51
{
43
- code : `test('verifies recursive expect method call', () => tester.foo().bar().expect(456));` ,
52
+ code : dedent `
53
+ test('verifies chained expect method call', () => {
54
+ tester
55
+ .foo()
56
+ .bar()
57
+ .expect(456);
58
+ });
59
+ ` ,
44
60
options : [ { assertFunctionNames : [ 'tester.foo.bar.expect' ] } ] ,
45
61
} ,
46
62
{
47
- code : [
48
- ' test("verifies the function call", () => {' ,
49
- ' td.verify(someFunctionCall())' ,
50
- '})' ,
51
- ] . join ( '\n' ) ,
63
+ code : dedent `
64
+ test("verifies the function call", () => {
65
+ td.verify(someFunctionCall())
66
+ })
67
+ ` ,
52
68
options : [ { assertFunctionNames : [ 'td.verify' ] } ] ,
53
69
} ,
54
70
{
@@ -125,41 +141,41 @@ ruleTester.run('expect-expect', rule, {
125
141
ruleTester . run ( 'wildcards' , rule , {
126
142
valid : [
127
143
{
128
- code : ` test('should pass', () => tester.foo().expect(123));` ,
144
+ code : " test('should pass', () => tester.foo().expect(123));" ,
129
145
options : [ { assertFunctionNames : [ 'tester.*.expect' ] } ] ,
130
146
} ,
131
147
{
132
- code : ` test('should pass **', () => tester.foo().expect(123));` ,
148
+ code : " test('should pass **', () => tester.foo().expect(123));" ,
133
149
options : [ { assertFunctionNames : [ '**' ] } ] ,
134
150
} ,
135
151
{
136
- code : ` test('should pass *', () => tester.foo().expect(123));` ,
152
+ code : " test('should pass *', () => tester.foo().expect(123));" ,
137
153
options : [ { assertFunctionNames : [ '*' ] } ] ,
138
154
} ,
139
155
{
140
- code : ` test('should pass', () => tester.foo().expect(123));` ,
156
+ code : " test('should pass', () => tester.foo().expect(123));" ,
141
157
options : [ { assertFunctionNames : [ 'tester.**' ] } ] ,
142
158
} ,
143
159
{
144
- code : ` test('should pass', () => tester.foo().expect(123));` ,
160
+ code : " test('should pass', () => tester.foo().expect(123));" ,
145
161
options : [ { assertFunctionNames : [ 'tester.*' ] } ] ,
146
162
} ,
147
163
{
148
- code : ` test('should pass', () => tester.foo().bar().expectIt(456));` ,
164
+ code : " test('should pass', () => tester.foo().bar().expectIt(456));" ,
149
165
options : [ { assertFunctionNames : [ 'tester.**.expect*' ] } ] ,
150
166
} ,
151
167
{
152
- code : ` test('should pass', () => request.get().foo().expect(456));` ,
168
+ code : " test('should pass', () => request.get().foo().expect(456));" ,
153
169
options : [ { assertFunctionNames : [ 'request.**.expect' ] } ] ,
154
170
} ,
155
171
{
156
- code : ` test('should pass', () => request.get().foo().expect(456));` ,
172
+ code : " test('should pass', () => request.get().foo().expect(456));" ,
157
173
options : [ { assertFunctionNames : [ 'request.**.e*e*t' ] } ] ,
158
174
} ,
159
175
] ,
160
176
invalid : [
161
177
{
162
- code : ` test('should fail', () => request.get().foo().expect(456));` ,
178
+ code : " test('should fail', () => request.get().foo().expect(456));" ,
163
179
options : [ { assertFunctionNames : [ 'request.*.expect' ] } ] ,
164
180
errors : [
165
181
{
@@ -169,7 +185,7 @@ ruleTester.run('wildcards', rule, {
169
185
] ,
170
186
} ,
171
187
{
172
- code : ` test('should fail', () => request.get().foo().bar().expect(456));` ,
188
+ code : " test('should fail', () => request.get().foo().bar().expect(456));" ,
173
189
options : [ { assertFunctionNames : [ 'request.foo**.expect' ] } ] ,
174
190
errors : [
175
191
{
@@ -179,7 +195,7 @@ ruleTester.run('wildcards', rule, {
179
195
] ,
180
196
} ,
181
197
{
182
- code : ` test('should fail', () => tester.request(123));` ,
198
+ code : " test('should fail', () => tester.request(123));" ,
183
199
options : [ { assertFunctionNames : [ 'request.*' ] } ] ,
184
200
errors : [
185
201
{
@@ -189,7 +205,7 @@ ruleTester.run('wildcards', rule, {
189
205
] ,
190
206
} ,
191
207
{
192
- code : ` test('should fail', () => request(123));` ,
208
+ code : " test('should fail', () => request(123));" ,
193
209
options : [ { assertFunctionNames : [ 'request.*' ] } ] ,
194
210
errors : [
195
211
{
@@ -199,7 +215,7 @@ ruleTester.run('wildcards', rule, {
199
215
] ,
200
216
} ,
201
217
{
202
- code : ` test('should fail', () => request(123));` ,
218
+ code : " test('should fail', () => request(123));" ,
203
219
options : [ { assertFunctionNames : [ 'request.**' ] } ] ,
204
220
errors : [
205
221
{
0 commit comments