|
| 1 | +import { TSESLint } from '@typescript-eslint/experimental-utils'; |
| 2 | +import rule from '../valid-title'; |
| 3 | + |
| 4 | +const ruleTester = new TSESLint.RuleTester({ |
| 5 | + parserOptions: { |
| 6 | + ecmaVersion: 8, |
| 7 | + }, |
| 8 | +}); |
| 9 | + |
| 10 | +ruleTester.run('no-accidental-space', rule, { |
| 11 | + valid: [ |
| 12 | + 'describe("foo", function () {})', |
| 13 | + 'describe(6, function () {})', |
| 14 | + 'fdescribe("foo", function () {})', |
| 15 | + 'xdescribe("foo", function () {})', |
| 16 | + 'it("foo", function () {})', |
| 17 | + 'fit("foo", function () {})', |
| 18 | + 'xit("foo", function () {})', |
| 19 | + 'test("foo", function () {})', |
| 20 | + 'xtest("foo", function () {})', |
| 21 | + 'someFn("foo", function () {})', |
| 22 | + ` |
| 23 | + describe('foo', () => { |
| 24 | + it('bar', () => {}) |
| 25 | + }) |
| 26 | + `, |
| 27 | + ], |
| 28 | + invalid: [ |
| 29 | + { |
| 30 | + code: 'describe(" foo", function () {})', |
| 31 | + errors: [{ messageId: 'accidentalSpace', column: 1, line: 1 }], |
| 32 | + }, |
| 33 | + { |
| 34 | + code: 'fdescribe(" foo", function () {})', |
| 35 | + errors: [{ messageId: 'accidentalSpace', column: 1, line: 1 }], |
| 36 | + }, |
| 37 | + { |
| 38 | + code: 'xdescribe(" foo", function () {})', |
| 39 | + errors: [{ messageId: 'accidentalSpace', column: 1, line: 1 }], |
| 40 | + }, |
| 41 | + { |
| 42 | + code: 'it(" foo", function () {})', |
| 43 | + errors: [{ messageId: 'accidentalSpace', column: 1, line: 1 }], |
| 44 | + }, |
| 45 | + { |
| 46 | + code: 'fit(" foo", function () {})', |
| 47 | + errors: [{ messageId: 'accidentalSpace', column: 1, line: 1 }], |
| 48 | + }, |
| 49 | + { |
| 50 | + code: 'xit(" foo", function () {})', |
| 51 | + errors: [{ messageId: 'accidentalSpace', column: 1, line: 1 }], |
| 52 | + }, |
| 53 | + { |
| 54 | + code: 'test(" foo", function () {})', |
| 55 | + errors: [{ messageId: 'accidentalSpace', column: 1, line: 1 }], |
| 56 | + }, |
| 57 | + { |
| 58 | + code: 'xtest(" foo", function () {})', |
| 59 | + errors: [{ messageId: 'accidentalSpace', column: 1, line: 1 }], |
| 60 | + }, |
| 61 | + { |
| 62 | + code: ` |
| 63 | + describe(' foo', () => { |
| 64 | + it('bar', () => {}) |
| 65 | + }) |
| 66 | + `, |
| 67 | + errors: [{ messageId: 'accidentalSpace', column: 7, line: 2 }], |
| 68 | + }, |
| 69 | + { |
| 70 | + code: ` |
| 71 | + describe('foo', () => { |
| 72 | + it(' bar', () => {}) |
| 73 | + }) |
| 74 | + `, |
| 75 | + errors: [{ messageId: 'accidentalSpace', column: 9, line: 3 }], |
| 76 | + }, |
| 77 | + ], |
| 78 | +}); |
| 79 | + |
| 80 | +ruleTester.run('no-duplicate-prefix ft describe', rule, { |
| 81 | + valid: [ |
| 82 | + 'describe("foo", function () {})', |
| 83 | + 'fdescribe("foo", function () {})', |
| 84 | + 'xdescribe("foo", function () {})', |
| 85 | + ], |
| 86 | + invalid: [ |
| 87 | + { |
| 88 | + code: 'describe("describe foo", function () {})', |
| 89 | + errors: [{ messageId: 'duplicatePrefix', column: 1, line: 1 }], |
| 90 | + }, |
| 91 | + { |
| 92 | + code: 'fdescribe("describe foo", function () {})', |
| 93 | + errors: [{ messageId: 'duplicatePrefix', column: 1, line: 1 }], |
| 94 | + }, |
| 95 | + { |
| 96 | + code: 'xdescribe("describe foo", function () {})', |
| 97 | + errors: [{ messageId: 'duplicatePrefix', column: 1, line: 1 }], |
| 98 | + }, |
| 99 | + ], |
| 100 | +}); |
| 101 | + |
| 102 | +ruleTester.run('no-duplicate-prefix ft test', rule, { |
| 103 | + valid: ['test("foo", function () {})', 'xtest("foo", function () {})'], |
| 104 | + invalid: [ |
| 105 | + { |
| 106 | + code: 'test("test foo", function () {})', |
| 107 | + errors: [{ messageId: 'duplicatePrefix', column: 1, line: 1 }], |
| 108 | + }, |
| 109 | + { |
| 110 | + code: 'xtest("test foo", function () {})', |
| 111 | + errors: [{ messageId: 'duplicatePrefix', column: 1, line: 1 }], |
| 112 | + }, |
| 113 | + ], |
| 114 | +}); |
| 115 | + |
| 116 | +ruleTester.run('no-duplicate-prefix ft it', rule, { |
| 117 | + valid: [ |
| 118 | + 'it("foo", function () {})', |
| 119 | + 'fit("foo", function () {})', |
| 120 | + 'xit("foo", function () {})', |
| 121 | + ], |
| 122 | + invalid: [ |
| 123 | + { |
| 124 | + code: 'it("it foo", function () {})', |
| 125 | + errors: [{ messageId: 'duplicatePrefix', column: 1, line: 1 }], |
| 126 | + }, |
| 127 | + { |
| 128 | + code: 'fit("it foo", function () {})', |
| 129 | + errors: [{ messageId: 'duplicatePrefix', column: 1, line: 1 }], |
| 130 | + }, |
| 131 | + { |
| 132 | + code: 'xit("it foo", function () {})', |
| 133 | + errors: [{ messageId: 'duplicatePrefix', column: 1, line: 1 }], |
| 134 | + }, |
| 135 | + ], |
| 136 | +}); |
| 137 | + |
| 138 | +ruleTester.run('no-duplicate-prefix ft nested', rule, { |
| 139 | + valid: [ |
| 140 | + ` |
| 141 | + describe('foo', () => { |
| 142 | + it('bar', () => {}) |
| 143 | + })`, |
| 144 | + ], |
| 145 | + invalid: [ |
| 146 | + { |
| 147 | + code: ` |
| 148 | + describe('describe foo', () => { |
| 149 | + it('bar', () => {}) |
| 150 | + })`, |
| 151 | + errors: [{ messageId: 'duplicatePrefix', column: 7, line: 2 }], |
| 152 | + }, |
| 153 | + { |
| 154 | + code: ` |
| 155 | + describe('foo', () => { |
| 156 | + it('it bar', () => {}) |
| 157 | + })`, |
| 158 | + errors: [{ messageId: 'duplicatePrefix', column: 9, line: 3 }], |
| 159 | + }, |
| 160 | + ], |
| 161 | +}); |
0 commit comments