/
no-hooks.test.js
45 lines (42 loc) · 1.11 KB
/
no-hooks.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
const { RuleTester } = require('eslint');
const rule = require('../no-hooks');
const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 6,
},
});
ruleTester.run('no-hooks', rule, {
valid: [
'test("foo")',
'describe("foo", () => { it("bar") })',
'test("foo", () => { expect(subject.beforeEach()).toBe(true) })',
{
code: 'afterEach(() => {}); afterAll(() => {});',
options: [{ allow: ['afterEach', 'afterAll'] }],
},
],
invalid: [
{
code: 'beforeAll(() => {})',
errors: [{ message: "Unexpected 'beforeAll' hook" }],
},
{
code: 'beforeEach(() => {})',
errors: [{ message: "Unexpected 'beforeEach' hook" }],
},
{
code: 'afterAll(() => {})',
errors: [{ message: "Unexpected 'afterAll' hook" }],
},
{
code: 'afterEach(() => {})',
errors: [{ message: "Unexpected 'afterEach' hook" }],
},
{
code: 'beforeEach(() => {}); afterEach(() => { jest.resetModules() });',
options: [{ allow: ['afterEach'] }],
errors: [{ message: "Unexpected 'beforeEach' hook" }],
},
],
});