|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const RuleTester = require('eslint').RuleTester; |
| 4 | +const rule = require('../no-jasmine-globals'); |
| 5 | + |
| 6 | +const ruleTester = new RuleTester(); |
| 7 | + |
| 8 | +ruleTester.run('no-jasmine-globals', rule, { |
| 9 | + valid: [ |
| 10 | + 'jest.spyOn()', |
| 11 | + 'jest.fn()', |
| 12 | + 'expect.extend()', |
| 13 | + 'expect.any()', |
| 14 | + 'it("foo", function () {})', |
| 15 | + 'test("foo", function () {})', |
| 16 | + 'foo()', |
| 17 | + ], |
| 18 | + invalid: [ |
| 19 | + { |
| 20 | + code: 'spyOn(some, "object")', |
| 21 | + errors: [ |
| 22 | + { |
| 23 | + message: 'Illegal usage of global `spyOn`, prefer `jest.spyOn`', |
| 24 | + column: 1, |
| 25 | + line: 1, |
| 26 | + }, |
| 27 | + ], |
| 28 | + }, |
| 29 | + { |
| 30 | + code: 'spyOnProperty(some, "object")', |
| 31 | + errors: [ |
| 32 | + { |
| 33 | + message: |
| 34 | + 'Illegal usage of global `spyOnProperty`, prefer `jest.spyOn`', |
| 35 | + column: 1, |
| 36 | + line: 1, |
| 37 | + }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + { |
| 41 | + code: 'fail()', |
| 42 | + errors: [ |
| 43 | + { |
| 44 | + message: |
| 45 | + 'Illegal usage of `fail`, prefer throwing an error, or the `done.fail` callback', |
| 46 | + column: 1, |
| 47 | + line: 1, |
| 48 | + }, |
| 49 | + ], |
| 50 | + }, |
| 51 | + { |
| 52 | + code: 'pending()', |
| 53 | + errors: [ |
| 54 | + { |
| 55 | + message: |
| 56 | + 'Illegal usage of `pending`, prefer explicitly skipping a test using `test.skip`', |
| 57 | + column: 1, |
| 58 | + line: 1, |
| 59 | + }, |
| 60 | + ], |
| 61 | + }, |
| 62 | + { |
| 63 | + code: 'jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;', |
| 64 | + errors: [ |
| 65 | + { |
| 66 | + message: 'Illegal usage of jasmine global', |
| 67 | + column: 1, |
| 68 | + line: 1, |
| 69 | + }, |
| 70 | + ], |
| 71 | + output: 'jest.setTimeout(5000);', |
| 72 | + }, |
| 73 | + { |
| 74 | + code: 'jasmine.addMatchers(matchers)', |
| 75 | + errors: [ |
| 76 | + { |
| 77 | + message: |
| 78 | + 'Illegal usage of `jasmine.addMatchers`, prefer `expect.extend`', |
| 79 | + column: 1, |
| 80 | + line: 1, |
| 81 | + }, |
| 82 | + ], |
| 83 | + }, |
| 84 | + { |
| 85 | + code: 'jasmine.createSpy()', |
| 86 | + errors: [ |
| 87 | + { |
| 88 | + message: 'Illegal usage of `jasmine.createSpy`, prefer `jest.fn`', |
| 89 | + column: 1, |
| 90 | + line: 1, |
| 91 | + }, |
| 92 | + ], |
| 93 | + }, |
| 94 | + { |
| 95 | + code: 'jasmine.any()', |
| 96 | + errors: [ |
| 97 | + { |
| 98 | + message: 'Illegal usage of `jasmine.any`, prefer `expect.any`', |
| 99 | + column: 1, |
| 100 | + line: 1, |
| 101 | + }, |
| 102 | + ], |
| 103 | + output: 'expect.any()', |
| 104 | + }, |
| 105 | + { |
| 106 | + code: 'jasmine.anything()', |
| 107 | + errors: [ |
| 108 | + { |
| 109 | + message: |
| 110 | + 'Illegal usage of `jasmine.anything`, prefer `expect.anything`', |
| 111 | + column: 1, |
| 112 | + line: 1, |
| 113 | + }, |
| 114 | + ], |
| 115 | + output: 'expect.anything()', |
| 116 | + }, |
| 117 | + { |
| 118 | + code: 'jasmine.arrayContaining()', |
| 119 | + errors: [ |
| 120 | + { |
| 121 | + message: |
| 122 | + 'Illegal usage of `jasmine.arrayContaining`, prefer `expect.arrayContaining`', |
| 123 | + column: 1, |
| 124 | + line: 1, |
| 125 | + }, |
| 126 | + ], |
| 127 | + output: 'expect.arrayContaining()', |
| 128 | + }, |
| 129 | + { |
| 130 | + code: 'jasmine.objectContaining()', |
| 131 | + errors: [ |
| 132 | + { |
| 133 | + message: |
| 134 | + 'Illegal usage of `jasmine.objectContaining`, prefer `expect.objectContaining`', |
| 135 | + column: 1, |
| 136 | + line: 1, |
| 137 | + }, |
| 138 | + ], |
| 139 | + output: 'expect.objectContaining()', |
| 140 | + }, |
| 141 | + { |
| 142 | + code: 'jasmine.stringMatching()', |
| 143 | + errors: [ |
| 144 | + { |
| 145 | + message: |
| 146 | + 'Illegal usage of `jasmine.stringMatching`, prefer `expect.stringMatching`', |
| 147 | + column: 1, |
| 148 | + line: 1, |
| 149 | + }, |
| 150 | + ], |
| 151 | + output: 'expect.stringMatching()', |
| 152 | + }, |
| 153 | + { |
| 154 | + code: 'jasmine.getEnv()', |
| 155 | + errors: [ |
| 156 | + { |
| 157 | + message: 'Illegal usage of jasmine global', |
| 158 | + column: 1, |
| 159 | + line: 1, |
| 160 | + }, |
| 161 | + ], |
| 162 | + }, |
| 163 | + { |
| 164 | + code: 'jasmine.empty()', |
| 165 | + errors: [ |
| 166 | + { |
| 167 | + message: 'Illegal usage of jasmine global', |
| 168 | + column: 1, |
| 169 | + line: 1, |
| 170 | + }, |
| 171 | + ], |
| 172 | + }, |
| 173 | + { |
| 174 | + code: 'jasmine.falsy()', |
| 175 | + errors: [ |
| 176 | + { |
| 177 | + message: 'Illegal usage of jasmine global', |
| 178 | + column: 1, |
| 179 | + line: 1, |
| 180 | + }, |
| 181 | + ], |
| 182 | + }, |
| 183 | + { |
| 184 | + code: 'jasmine.truthy()', |
| 185 | + errors: [ |
| 186 | + { |
| 187 | + message: 'Illegal usage of jasmine global', |
| 188 | + column: 1, |
| 189 | + line: 1, |
| 190 | + }, |
| 191 | + ], |
| 192 | + }, |
| 193 | + { |
| 194 | + code: 'jasmine.arrayWithExactContents()', |
| 195 | + errors: [ |
| 196 | + { |
| 197 | + message: 'Illegal usage of jasmine global', |
| 198 | + column: 1, |
| 199 | + line: 1, |
| 200 | + }, |
| 201 | + ], |
| 202 | + }, |
| 203 | + { |
| 204 | + code: 'jasmine.clock()', |
| 205 | + errors: [ |
| 206 | + { |
| 207 | + message: 'Illegal usage of jasmine global', |
| 208 | + column: 1, |
| 209 | + line: 1, |
| 210 | + }, |
| 211 | + ], |
| 212 | + }, |
| 213 | + { |
| 214 | + code: 'jasmine.MAX_PRETTY_PRINT_ARRAY_LENGTH = 42', |
| 215 | + errors: [ |
| 216 | + { |
| 217 | + message: 'Illegal usage of jasmine global', |
| 218 | + column: 1, |
| 219 | + line: 1, |
| 220 | + }, |
| 221 | + ], |
| 222 | + }, |
| 223 | + ], |
| 224 | +}); |
0 commit comments