|
| 1 | +package prefer_called_with_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/web-infra-dev/rslint/internal/plugins/jest/fixtures" |
| 7 | + "github.com/web-infra-dev/rslint/internal/plugins/jest/rules/prefer_called_with" |
| 8 | + "github.com/web-infra-dev/rslint/internal/rule_tester" |
| 9 | +) |
| 10 | + |
| 11 | +func TestPreferCalledWithRule(t *testing.T) { |
| 12 | + rule_tester.RunRuleTester( |
| 13 | + fixtures.GetRootDir(), |
| 14 | + "tsconfig.json", |
| 15 | + t, |
| 16 | + &prefer_called_with.PreferCalledWithRule, |
| 17 | + []rule_tester.ValidTestCase{ |
| 18 | + {Code: `expect(fn).toBeCalledWith();`}, |
| 19 | + {Code: `expect(fn).toHaveBeenCalledWith();`}, |
| 20 | + {Code: `expect(fn).toBeCalledWith(expect.anything());`}, |
| 21 | + {Code: `expect(fn).toHaveBeenCalledWith(expect.anything());`}, |
| 22 | + {Code: `expect(fn).not.toBeCalled();`}, |
| 23 | + {Code: `expect(fn).rejects.not.toBeCalled();`}, |
| 24 | + {Code: `expect(fn).not.toHaveBeenCalled();`}, |
| 25 | + {Code: `expect(fn).not.toBeCalledWith();`}, |
| 26 | + {Code: `expect(fn).not.toHaveBeenCalledWith();`}, |
| 27 | + {Code: `expect(fn).resolves.not.toHaveBeenCalledWith();`}, |
| 28 | + {Code: `expect(fn).toBeCalledTimes(0);`}, |
| 29 | + {Code: `expect(fn).toHaveBeenCalledTimes(0);`}, |
| 30 | + {Code: `expect(fn);`}, |
| 31 | + }, |
| 32 | + []rule_tester.InvalidTestCase{ |
| 33 | + { |
| 34 | + Code: `expect(fn).toBeCalled();`, |
| 35 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 36 | + {MessageId: "preferCalledWith", Line: 1, Column: 12}, |
| 37 | + }, |
| 38 | + }, |
| 39 | + { |
| 40 | + Code: `expect(fn).resolves.toBeCalled();`, |
| 41 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 42 | + {MessageId: "preferCalledWith", Line: 1, Column: 21}, |
| 43 | + }, |
| 44 | + }, |
| 45 | + { |
| 46 | + Code: `expect(fn).toHaveBeenCalled();`, |
| 47 | + Errors: []rule_tester.InvalidTestCaseError{ |
| 48 | + {MessageId: "preferCalledWith", Line: 1, Column: 12}, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + ) |
| 53 | +} |
0 commit comments