Skip to content

Commit

Permalink
test(expect-expect): use dedent for multi-line cases (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Sep 27, 2020
1 parent c8a040a commit a64d505
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions src/rules/__tests__/expect-expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AST_NODE_TYPES,
TSESLint,
} from '@typescript-eslint/experimental-utils';
import dedent from 'dedent';
import resolveFrom from 'resolve-from';
import rule from '../expect-expect';

Expand All @@ -19,8 +20,12 @@ ruleTester.run('expect-expect', rule, {
'it("should pass", () => somePromise().then(() => expect(true).toBeDefined()))',
'it("should pass", myTest); function myTest() { expect(true).toBeDefined() }',
{
code:
'test("should pass", () => { expect(true).toBeDefined(); foo(true).toBe(true); })',
code: dedent`
test('should pass', () => {
expect(true).toBeDefined();
foo(true).toBe(true);
});
`,
options: [{ assertFunctionNames: ['expect', 'foo'] }],
},
{
Expand All @@ -32,23 +37,34 @@ ruleTester.run('expect-expect', rule, {
options: [{ assertFunctionNames: ['expect\\$'] }],
},
{
code: `test('verifies expect method call', () => new Foo().expect(123));`,
code: "test('verifies expect method call', () => new Foo().expect(123));",
options: [{ assertFunctionNames: ['Foo.expect'] }],
},
{
code: `test('verifies deep expect method call', () => tester.foo().expect(123));`,
code: dedent`
test('verifies deep expect method call', () => {
tester.foo().expect(123);
});
`,
options: [{ assertFunctionNames: ['tester.foo.expect'] }],
},
{
code: `test('verifies recursive expect method call', () => tester.foo().bar().expect(456));`,
code: dedent`
test('verifies chained expect method call', () => {
tester
.foo()
.bar()
.expect(456);
});
`,
options: [{ assertFunctionNames: ['tester.foo.bar.expect'] }],
},
{
code: [
'test("verifies the function call", () => {',
' td.verify(someFunctionCall())',
'})',
].join('\n'),
code: dedent`
test("verifies the function call", () => {
td.verify(someFunctionCall())
})
`,
options: [{ assertFunctionNames: ['td.verify'] }],
},
{
Expand Down Expand Up @@ -125,41 +141,41 @@ ruleTester.run('expect-expect', rule, {
ruleTester.run('wildcards', rule, {
valid: [
{
code: `test('should pass', () => tester.foo().expect(123));`,
code: "test('should pass', () => tester.foo().expect(123));",
options: [{ assertFunctionNames: ['tester.*.expect'] }],
},
{
code: `test('should pass **', () => tester.foo().expect(123));`,
code: "test('should pass **', () => tester.foo().expect(123));",
options: [{ assertFunctionNames: ['**'] }],
},
{
code: `test('should pass *', () => tester.foo().expect(123));`,
code: "test('should pass *', () => tester.foo().expect(123));",
options: [{ assertFunctionNames: ['*'] }],
},
{
code: `test('should pass', () => tester.foo().expect(123));`,
code: "test('should pass', () => tester.foo().expect(123));",
options: [{ assertFunctionNames: ['tester.**'] }],
},
{
code: `test('should pass', () => tester.foo().expect(123));`,
code: "test('should pass', () => tester.foo().expect(123));",
options: [{ assertFunctionNames: ['tester.*'] }],
},
{
code: `test('should pass', () => tester.foo().bar().expectIt(456));`,
code: "test('should pass', () => tester.foo().bar().expectIt(456));",
options: [{ assertFunctionNames: ['tester.**.expect*'] }],
},
{
code: `test('should pass', () => request.get().foo().expect(456));`,
code: "test('should pass', () => request.get().foo().expect(456));",
options: [{ assertFunctionNames: ['request.**.expect'] }],
},
{
code: `test('should pass', () => request.get().foo().expect(456));`,
code: "test('should pass', () => request.get().foo().expect(456));",
options: [{ assertFunctionNames: ['request.**.e*e*t'] }],
},
],
invalid: [
{
code: `test('should fail', () => request.get().foo().expect(456));`,
code: "test('should fail', () => request.get().foo().expect(456));",
options: [{ assertFunctionNames: ['request.*.expect'] }],
errors: [
{
Expand All @@ -169,7 +185,7 @@ ruleTester.run('wildcards', rule, {
],
},
{
code: `test('should fail', () => request.get().foo().bar().expect(456));`,
code: "test('should fail', () => request.get().foo().bar().expect(456));",
options: [{ assertFunctionNames: ['request.foo**.expect'] }],
errors: [
{
Expand All @@ -179,7 +195,7 @@ ruleTester.run('wildcards', rule, {
],
},
{
code: `test('should fail', () => tester.request(123));`,
code: "test('should fail', () => tester.request(123));",
options: [{ assertFunctionNames: ['request.*'] }],
errors: [
{
Expand All @@ -189,7 +205,7 @@ ruleTester.run('wildcards', rule, {
],
},
{
code: `test('should fail', () => request(123));`,
code: "test('should fail', () => request(123));",
options: [{ assertFunctionNames: ['request.*'] }],
errors: [
{
Expand All @@ -199,7 +215,7 @@ ruleTester.run('wildcards', rule, {
],
},
{
code: `test('should fail', () => request(123));`,
code: "test('should fail', () => request(123));",
options: [{ assertFunctionNames: ['request.**'] }],
errors: [
{
Expand Down

0 comments on commit a64d505

Please sign in to comment.