|
| 1 | +import RuleTester, {testCase} from './helpers/rule-tester.js'; |
| 2 | +import rule from '../rules/no-negated-assertion.js'; |
| 3 | + |
| 4 | +const ruleTester = new RuleTester(); |
| 5 | + |
| 6 | +const errors = [{messageId: 'no-negated-assertion'}]; |
| 7 | + |
| 8 | +ruleTester.run('no-negated-assertion', rule, { |
| 9 | + valid: [ |
| 10 | + testCase('t.true(x)'), |
| 11 | + testCase('t.false(x)'), |
| 12 | + testCase('t.truthy(x)'), |
| 13 | + testCase('t.falsy(x)'), |
| 14 | + testCase('t.is(!x, y)'), |
| 15 | + testCase('t.assert(!x)'), |
| 16 | + testCase('t.true(x, "message")'), |
| 17 | + testCase('t.true()'), |
| 18 | + // Not a test object |
| 19 | + testCase('foo.true(!x)'), |
| 20 | + // `t.context` is not an assertion |
| 21 | + testCase('t.context.true(!x)'), |
| 22 | + // Invalid modifier order; handled by other rules |
| 23 | + testCase('t.skip.true(!x)'), |
| 24 | + // Invalid trailing member; handled by other rules |
| 25 | + testCase('t.true.context(!x)'), |
| 26 | + // Shouldn't be triggered since it's not a test file |
| 27 | + {code: testCase('t.true(!x)'), noHeader: true}, |
| 28 | + ], |
| 29 | + invalid: [ |
| 30 | + { |
| 31 | + code: testCase('t.true(!x)'), |
| 32 | + output: testCase('t.falsy(x)'), |
| 33 | + errors, |
| 34 | + }, |
| 35 | + { |
| 36 | + code: testCase('t.false(!x)'), |
| 37 | + output: testCase('t.truthy(x)'), |
| 38 | + errors, |
| 39 | + }, |
| 40 | + { |
| 41 | + code: testCase('t.truthy(!x)'), |
| 42 | + output: testCase('t.falsy(x)'), |
| 43 | + errors, |
| 44 | + }, |
| 45 | + { |
| 46 | + code: testCase('t.falsy(!x)'), |
| 47 | + output: testCase('t.truthy(x)'), |
| 48 | + errors, |
| 49 | + }, |
| 50 | + // With message argument |
| 51 | + { |
| 52 | + code: testCase('t.true(!x, "msg")'), |
| 53 | + output: testCase('t.falsy(x, "msg")'), |
| 54 | + errors, |
| 55 | + }, |
| 56 | + // Complex expressions |
| 57 | + { |
| 58 | + code: testCase('t.true(!foo.bar)'), |
| 59 | + output: testCase('t.falsy(foo.bar)'), |
| 60 | + errors, |
| 61 | + }, |
| 62 | + { |
| 63 | + code: testCase('t.true(!foo())'), |
| 64 | + output: testCase('t.falsy(foo())'), |
| 65 | + errors, |
| 66 | + }, |
| 67 | + { |
| 68 | + code: testCase('t.true(!(a === b))'), |
| 69 | + output: testCase('t.falsy(a === b)'), |
| 70 | + errors, |
| 71 | + }, |
| 72 | + { |
| 73 | + code: testCase('t.true(!(a, b))'), |
| 74 | + output: testCase('t.falsy((a, b))'), |
| 75 | + errors, |
| 76 | + }, |
| 77 | + // With .skip |
| 78 | + { |
| 79 | + code: testCase('t.true.skip(!x)'), |
| 80 | + output: testCase('t.falsy.skip(x)'), |
| 81 | + errors, |
| 82 | + }, |
| 83 | + { |
| 84 | + code: testCase('t.truthy.skip(!x)'), |
| 85 | + output: testCase('t.falsy.skip(x)'), |
| 86 | + errors, |
| 87 | + }, |
| 88 | + { |
| 89 | + code: testCase('t.true.skip.skip(!x)'), |
| 90 | + output: testCase('t.falsy.skip.skip(x)'), |
| 91 | + errors, |
| 92 | + }, |
| 93 | + // Double negation |
| 94 | + { |
| 95 | + code: testCase('t.true(!!x)'), |
| 96 | + output: testCase('t.truthy(x)'), |
| 97 | + errors, |
| 98 | + }, |
| 99 | + { |
| 100 | + code: testCase('t.false(!!x)'), |
| 101 | + output: testCase('t.falsy(x)'), |
| 102 | + errors, |
| 103 | + }, |
| 104 | + { |
| 105 | + code: testCase('t.truthy(!!x)'), |
| 106 | + output: testCase('t.truthy(x)'), |
| 107 | + errors, |
| 108 | + }, |
| 109 | + { |
| 110 | + code: testCase('t.true.skip(!!x)'), |
| 111 | + output: testCase('t.truthy.skip(x)'), |
| 112 | + errors, |
| 113 | + }, |
| 114 | + { |
| 115 | + code: testCase('t.true(!!(a, b))'), |
| 116 | + output: testCase('t.truthy((a, b))'), |
| 117 | + errors, |
| 118 | + }, |
| 119 | + // Non-boolean values |
| 120 | + { |
| 121 | + code: testCase('t.true(!0)'), |
| 122 | + output: testCase('t.falsy(0)'), |
| 123 | + errors, |
| 124 | + }, |
| 125 | + { |
| 126 | + code: testCase('t.false(!0)'), |
| 127 | + output: testCase('t.truthy(0)'), |
| 128 | + errors, |
| 129 | + }, |
| 130 | + { |
| 131 | + code: testCase('t.true(!!1)'), |
| 132 | + output: testCase('t.truthy(1)'), |
| 133 | + errors, |
| 134 | + }, |
| 135 | + { |
| 136 | + code: testCase('t.false(!!1)'), |
| 137 | + output: testCase('t.falsy(1)'), |
| 138 | + errors, |
| 139 | + }, |
| 140 | + // Alternative test object names |
| 141 | + { |
| 142 | + code: testCase('tt.true(!x)'), |
| 143 | + output: testCase('tt.falsy(x)'), |
| 144 | + errors, |
| 145 | + }, |
| 146 | + ], |
| 147 | +}); |
0 commit comments