|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const RuleTester = require('eslint').RuleTester; |
| 4 | +const rules = require('../..').rules; |
| 5 | + |
| 6 | +const ruleTester = new RuleTester({ |
| 7 | + parserOptions: { |
| 8 | + ecmaVersion: 8, |
| 9 | + }, |
| 10 | +}); |
| 11 | + |
| 12 | +ruleTester.run('valid-describe', rules['valid-describe'], { |
| 13 | + valid: [ |
| 14 | + 'describe("foo")', |
| 15 | + 'describe("foo", function() {})', |
| 16 | + 'describe("foo", () => {})', |
| 17 | + 'xdescribe("foo", () => {})', |
| 18 | + 'fdescribe("foo", () => {})', |
| 19 | + 'describe.only("foo", () => {})', |
| 20 | + 'describe.skip("foo", () => {})', |
| 21 | + ` |
| 22 | + describe('foo', () => { |
| 23 | + it('bar', () => { |
| 24 | + return Promise.resolve(42).then(value => { |
| 25 | + expect(value).toBe(42) |
| 26 | + }) |
| 27 | + }) |
| 28 | + }) |
| 29 | + `, |
| 30 | + ` |
| 31 | + describe('foo', () => { |
| 32 | + it('bar', async () => { |
| 33 | + expect(await Promise.resolve(42)).toBe(42) |
| 34 | + }) |
| 35 | + }) |
| 36 | + `, |
| 37 | + ], |
| 38 | + invalid: [ |
| 39 | + { |
| 40 | + code: 'describe("foo", async () => {})', |
| 41 | + errors: [{ message: 'No async describe callback', line: 1, column: 17 }], |
| 42 | + }, |
| 43 | + { |
| 44 | + code: 'describe("foo", async function () {})', |
| 45 | + errors: [{ message: 'No async describe callback', line: 1, column: 17 }], |
| 46 | + }, |
| 47 | + { |
| 48 | + code: 'xdescribe("foo", async function () {})', |
| 49 | + errors: [{ message: 'No async describe callback', line: 1, column: 18 }], |
| 50 | + }, |
| 51 | + { |
| 52 | + code: 'fdescribe("foo", async function () {})', |
| 53 | + errors: [{ message: 'No async describe callback', line: 1, column: 18 }], |
| 54 | + }, |
| 55 | + { |
| 56 | + code: 'describe.only("foo", async function () {})', |
| 57 | + errors: [{ message: 'No async describe callback', line: 1, column: 22 }], |
| 58 | + }, |
| 59 | + { |
| 60 | + code: 'describe.skip("foo", async function () {})', |
| 61 | + errors: [{ message: 'No async describe callback', line: 1, column: 22 }], |
| 62 | + }, |
| 63 | + { |
| 64 | + code: ` |
| 65 | + describe('sample case', () => { |
| 66 | + it('works', () => { |
| 67 | + expect(true).toEqual(true); |
| 68 | + }); |
| 69 | + describe('async', async () => { |
| 70 | + await new Promise(setImmediate); |
| 71 | + it('breaks', () => { |
| 72 | + throw new Error('Fail'); |
| 73 | + }); |
| 74 | + }); |
| 75 | + });`, |
| 76 | + errors: [{ message: 'No async describe callback', line: 6, column: 27 }], |
| 77 | + }, |
| 78 | + { |
| 79 | + code: ` |
| 80 | + describe('foo', function () { |
| 81 | + return Promise.resolve().then(() => { |
| 82 | + it('breaks', () => { |
| 83 | + throw new Error('Fail') |
| 84 | + }) |
| 85 | + }) |
| 86 | + }) |
| 87 | + `, |
| 88 | + errors: [ |
| 89 | + { |
| 90 | + message: 'Unexpected return statement in describe callback', |
| 91 | + line: 3, |
| 92 | + column: 9, |
| 93 | + }, |
| 94 | + ], |
| 95 | + }, |
| 96 | + { |
| 97 | + code: ` |
| 98 | + describe('foo', () => { |
| 99 | + return Promise.resolve().then(() => { |
| 100 | + it('breaks', () => { |
| 101 | + throw new Error('Fail') |
| 102 | + }) |
| 103 | + }) |
| 104 | + describe('nested', () => { |
| 105 | + return Promise.resolve().then(() => { |
| 106 | + it('breaks', () => { |
| 107 | + throw new Error('Fail') |
| 108 | + }) |
| 109 | + }) |
| 110 | + }) |
| 111 | + }) |
| 112 | + `, |
| 113 | + errors: [ |
| 114 | + { |
| 115 | + message: 'Unexpected return statement in describe callback', |
| 116 | + line: 3, |
| 117 | + column: 9, |
| 118 | + }, |
| 119 | + { |
| 120 | + message: 'Unexpected return statement in describe callback', |
| 121 | + line: 9, |
| 122 | + column: 11, |
| 123 | + }, |
| 124 | + ], |
| 125 | + }, |
| 126 | + { |
| 127 | + code: ` |
| 128 | + describe('foo', async () => { |
| 129 | + await something() |
| 130 | + it('does something') |
| 131 | + describe('nested', () => { |
| 132 | + return Promise.resolve().then(() => { |
| 133 | + it('breaks', () => { |
| 134 | + throw new Error('Fail') |
| 135 | + }) |
| 136 | + }) |
| 137 | + }) |
| 138 | + }) |
| 139 | + `, |
| 140 | + errors: [ |
| 141 | + { |
| 142 | + message: 'No async describe callback', |
| 143 | + line: 2, |
| 144 | + column: 23, |
| 145 | + }, |
| 146 | + { |
| 147 | + message: 'Unexpected return statement in describe callback', |
| 148 | + line: 6, |
| 149 | + column: 11, |
| 150 | + }, |
| 151 | + ], |
| 152 | + }, |
| 153 | + { |
| 154 | + code: 'describe("foo", done => {})', |
| 155 | + errors: [ |
| 156 | + { |
| 157 | + message: 'Unexpected argument(s) in describe callback', |
| 158 | + line: 1, |
| 159 | + column: 17, |
| 160 | + }, |
| 161 | + ], |
| 162 | + }, |
| 163 | + { |
| 164 | + code: 'describe("foo", function (done) {})', |
| 165 | + errors: [ |
| 166 | + { |
| 167 | + message: 'Unexpected argument(s) in describe callback', |
| 168 | + line: 1, |
| 169 | + column: 27, |
| 170 | + }, |
| 171 | + ], |
| 172 | + }, |
| 173 | + { |
| 174 | + code: 'describe("foo", function (one, two, three) {})', |
| 175 | + errors: [ |
| 176 | + { |
| 177 | + message: 'Unexpected argument(s) in describe callback', |
| 178 | + line: 1, |
| 179 | + column: 27, |
| 180 | + }, |
| 181 | + ], |
| 182 | + }, |
| 183 | + { |
| 184 | + code: 'describe("foo", async function (done) {})', |
| 185 | + errors: [ |
| 186 | + { message: 'No async describe callback', line: 1, column: 17 }, |
| 187 | + { |
| 188 | + message: 'Unexpected argument(s) in describe callback', |
| 189 | + line: 1, |
| 190 | + column: 33, |
| 191 | + }, |
| 192 | + ], |
| 193 | + }, |
| 194 | + ], |
| 195 | +}); |
0 commit comments