|
| 1 | +import rule, { RULE_NAME } from '../src/rules/prefer-strict-boolean-matchers' |
| 2 | +import { ruleTester } from './ruleTester' |
| 3 | + |
| 4 | +const messageIdTrue = 'preferToBeTrue' |
| 5 | +const messageIdFalse = 'preferToBeFalse' |
| 6 | + |
| 7 | +ruleTester.run(RULE_NAME, rule, { |
| 8 | + valid: [ |
| 9 | + '[].push(true)', |
| 10 | + '[].push(false)', |
| 11 | + 'expect("something");', |
| 12 | + 'expect(true).toBe(true);', |
| 13 | + 'expect(true).toBe(false);', |
| 14 | + 'expect(false).toBe(true);', |
| 15 | + 'expect(false).toBe(false);', |
| 16 | + 'expect(fal,se).toBe(true);', |
| 17 | + 'expect(fal,se).toBe(false);', |
| 18 | + 'expect(value).toEqual();', |
| 19 | + 'expect(value).not.toBe(true);', |
| 20 | + 'expect(value).not.toBe(false);', |
| 21 | + 'expect(value).not.toEqual();', |
| 22 | + 'expect(value).toBe(undefined);', |
| 23 | + 'expect(value).not.toBe(undefined);', |
| 24 | + 'expect(value).toBe();', |
| 25 | + 'expect(true).toMatchSnapshot();', |
| 26 | + 'expect("a string").toMatchSnapshot(true);', |
| 27 | + 'expect("a string").toMatchSnapshot(false);', |
| 28 | + 'expect("a string").not.toMatchSnapshot();', |
| 29 | + 'expect(something).toEqual(\'a string\');', |
| 30 | + 'expect(true).toBe', |
| 31 | + 'expectTypeOf(true).toBe()' |
| 32 | + ], |
| 33 | + invalid: [ |
| 34 | + { |
| 35 | + code: 'expect(false).toBeTruthy();', |
| 36 | + output: 'expect(false).toBe(true);', |
| 37 | + errors: [{ messageId: messageIdTrue, column: 15, line: 1 }] |
| 38 | + }, |
| 39 | + { |
| 40 | + code: 'expect(false).toBeFalsy();', |
| 41 | + output: 'expect(false).toBe(false);', |
| 42 | + errors: [{ messageId: messageIdFalse, column: 15, line: 1 }] |
| 43 | + }, |
| 44 | + { |
| 45 | + code: 'expectTypeOf(false).toBeTruthy();', |
| 46 | + output: 'expectTypeOf(false).toBe(true);', |
| 47 | + errors: [{ messageId: messageIdTrue, column: 21, line: 1 }] |
| 48 | + }, |
| 49 | + { |
| 50 | + code: 'expectTypeOf(false).toBeFalsy();', |
| 51 | + output: 'expectTypeOf(false).toBe(false);', |
| 52 | + errors: [{ messageId: messageIdFalse, column: 21, line: 1 }] |
| 53 | + }, |
| 54 | + { |
| 55 | + code: 'expect(wasSuccessful).toBeTruthy();', |
| 56 | + output: 'expect(wasSuccessful).toBe(true);', |
| 57 | + errors: [{ messageId: messageIdTrue, column: 23, line: 1 }] |
| 58 | + }, |
| 59 | + { |
| 60 | + code: 'expect(wasSuccessful).toBeFalsy();', |
| 61 | + output: 'expect(wasSuccessful).toBe(false);', |
| 62 | + errors: [{ messageId: messageIdFalse, column: 23, line: 1 }] |
| 63 | + }, |
| 64 | + { |
| 65 | + code: 'expect("a string").not.toBeTruthy();', |
| 66 | + output: 'expect("a string").not.toBe(true);', |
| 67 | + errors: [{ messageId: messageIdTrue, column: 24, line: 1 }] |
| 68 | + }, |
| 69 | + { |
| 70 | + code: 'expect("a string").not.toBeFalsy();', |
| 71 | + output: 'expect("a string").not.toBe(false);', |
| 72 | + errors: [{ messageId: messageIdFalse, column: 24, line: 1 }] |
| 73 | + } |
| 74 | + ] |
| 75 | +}) |
0 commit comments