-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(require-tothrow-message): cover more cases (#161)
- Loading branch information
Showing
3 changed files
with
62 additions
and
35 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters