/
require-tothrow-message.test.js
52 lines (44 loc) · 1.25 KB
/
require-tothrow-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
'use strict';
const RuleTester = require('eslint').RuleTester;
const rule = require('../require-tothrow-message');
const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion: 6,
},
});
ruleTester.run('require-tothrow-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: [
{ message: 'Add an error message to toThrow()', column: 41, line: 1 },
],
},
// Empty toThrowError
{
code: "expect(() => { throw new Error('a'); }).toThrowError();",
errors: [
{
message: 'Add an error message to toThrowError()',
column: 41,
line: 1,
},
],
},
],
});