/
require-to-throw-message.test.js
56 lines (49 loc) · 1.32 KB
/
require-to-throw-message.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
46
47
48
49
50
51
52
53
54
55
56
import { RuleTester } from 'eslint';
import rule from '../require-to-throw-message';
const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 6,
},
});
ruleTester.run('require-to-throw-message', rule, {
valid: [
// String
"expect(() => { throw new Error('a'); }).toThrow('a');",
"expect(() => { throw new Error('a'); }).toThrowError('a');",
// Template literal
"const a = 'a'; expect(() => { throw new Error('a'); }).toThrow(`${a}`);",
// Regex
"expect(() => { throw new Error('a'); }).toThrow(/^a$/);",
// Function
"expect(() => { throw new Error('a'); })" +
".toThrow((() => { return 'a'; })());",
// Allow no message for `not`.
"expect(() => { throw new Error('a'); }).not.toThrow();",
],
invalid: [
// Empty toThrow
{
code: "expect(() => { throw new Error('a'); }).toThrow();",
errors: [
{
messageId: 'requireRethrow',
data: { propertyName: 'toThrow' },
column: 41,
line: 1,
},
],
},
// Empty toThrowError
{
code: "expect(() => { throw new Error('a'); }).toThrowError();",
errors: [
{
messageId: 'requireRethrow',
data: { propertyName: 'toThrowError' },
column: 41,
line: 1,
},
],
},
],
});