Skip to content

Commit a64d505

Browse files
authored
test(expect-expect): use dedent for multi-line cases (#679)
1 parent c8a040a commit a64d505

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

src/rules/__tests__/expect-expect.test.ts

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
AST_NODE_TYPES,
33
TSESLint,
44
} from '@typescript-eslint/experimental-utils';
5+
import dedent from 'dedent';
56
import resolveFrom from 'resolve-from';
67
import rule from '../expect-expect';
78

@@ -19,8 +20,12 @@ ruleTester.run('expect-expect', rule, {
1920
'it("should pass", () => somePromise().then(() => expect(true).toBeDefined()))',
2021
'it("should pass", myTest); function myTest() { expect(true).toBeDefined() }',
2122
{
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+
`,
2429
options: [{ assertFunctionNames: ['expect', 'foo'] }],
2530
},
2631
{
@@ -32,23 +37,34 @@ ruleTester.run('expect-expect', rule, {
3237
options: [{ assertFunctionNames: ['expect\\$'] }],
3338
},
3439
{
35-
code: `test('verifies expect method call', () => new Foo().expect(123));`,
40+
code: "test('verifies expect method call', () => new Foo().expect(123));",
3641
options: [{ assertFunctionNames: ['Foo.expect'] }],
3742
},
3843
{
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+
`,
4049
options: [{ assertFunctionNames: ['tester.foo.expect'] }],
4150
},
4251
{
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+
`,
4460
options: [{ assertFunctionNames: ['tester.foo.bar.expect'] }],
4561
},
4662
{
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+
`,
5268
options: [{ assertFunctionNames: ['td.verify'] }],
5369
},
5470
{
@@ -125,41 +141,41 @@ ruleTester.run('expect-expect', rule, {
125141
ruleTester.run('wildcards', rule, {
126142
valid: [
127143
{
128-
code: `test('should pass', () => tester.foo().expect(123));`,
144+
code: "test('should pass', () => tester.foo().expect(123));",
129145
options: [{ assertFunctionNames: ['tester.*.expect'] }],
130146
},
131147
{
132-
code: `test('should pass **', () => tester.foo().expect(123));`,
148+
code: "test('should pass **', () => tester.foo().expect(123));",
133149
options: [{ assertFunctionNames: ['**'] }],
134150
},
135151
{
136-
code: `test('should pass *', () => tester.foo().expect(123));`,
152+
code: "test('should pass *', () => tester.foo().expect(123));",
137153
options: [{ assertFunctionNames: ['*'] }],
138154
},
139155
{
140-
code: `test('should pass', () => tester.foo().expect(123));`,
156+
code: "test('should pass', () => tester.foo().expect(123));",
141157
options: [{ assertFunctionNames: ['tester.**'] }],
142158
},
143159
{
144-
code: `test('should pass', () => tester.foo().expect(123));`,
160+
code: "test('should pass', () => tester.foo().expect(123));",
145161
options: [{ assertFunctionNames: ['tester.*'] }],
146162
},
147163
{
148-
code: `test('should pass', () => tester.foo().bar().expectIt(456));`,
164+
code: "test('should pass', () => tester.foo().bar().expectIt(456));",
149165
options: [{ assertFunctionNames: ['tester.**.expect*'] }],
150166
},
151167
{
152-
code: `test('should pass', () => request.get().foo().expect(456));`,
168+
code: "test('should pass', () => request.get().foo().expect(456));",
153169
options: [{ assertFunctionNames: ['request.**.expect'] }],
154170
},
155171
{
156-
code: `test('should pass', () => request.get().foo().expect(456));`,
172+
code: "test('should pass', () => request.get().foo().expect(456));",
157173
options: [{ assertFunctionNames: ['request.**.e*e*t'] }],
158174
},
159175
],
160176
invalid: [
161177
{
162-
code: `test('should fail', () => request.get().foo().expect(456));`,
178+
code: "test('should fail', () => request.get().foo().expect(456));",
163179
options: [{ assertFunctionNames: ['request.*.expect'] }],
164180
errors: [
165181
{
@@ -169,7 +185,7 @@ ruleTester.run('wildcards', rule, {
169185
],
170186
},
171187
{
172-
code: `test('should fail', () => request.get().foo().bar().expect(456));`,
188+
code: "test('should fail', () => request.get().foo().bar().expect(456));",
173189
options: [{ assertFunctionNames: ['request.foo**.expect'] }],
174190
errors: [
175191
{
@@ -179,7 +195,7 @@ ruleTester.run('wildcards', rule, {
179195
],
180196
},
181197
{
182-
code: `test('should fail', () => tester.request(123));`,
198+
code: "test('should fail', () => tester.request(123));",
183199
options: [{ assertFunctionNames: ['request.*'] }],
184200
errors: [
185201
{
@@ -189,7 +205,7 @@ ruleTester.run('wildcards', rule, {
189205
],
190206
},
191207
{
192-
code: `test('should fail', () => request(123));`,
208+
code: "test('should fail', () => request(123));",
193209
options: [{ assertFunctionNames: ['request.*'] }],
194210
errors: [
195211
{
@@ -199,7 +215,7 @@ ruleTester.run('wildcards', rule, {
199215
],
200216
},
201217
{
202-
code: `test('should fail', () => request(123));`,
218+
code: "test('should fail', () => request(123));",
203219
options: [{ assertFunctionNames: ['request.**'] }],
204220
errors: [
205221
{

0 commit comments

Comments
 (0)