-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn about unsafe toWarnDev() nesting in tests (#12457)
* Add lint run to warn about improperly nested toWarnDev matchers * Updated tests to avoid invalid nesting
- Loading branch information
Showing
8 changed files
with
160 additions
and
84 deletions.
There are no files selected for viewing
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
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
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
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
32 changes: 32 additions & 0 deletions
32
scripts/eslint-rules/__tests__/no-to-warn-dev-within-to-throw-test.internal.js
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,32 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const rule = require('../no-to-warn-dev-within-to-throw'); | ||
const RuleTester = require('eslint').RuleTester; | ||
const ruleTester = new RuleTester(); | ||
|
||
ruleTester.run('eslint-rules/no-to-warn-dev-within-to-throw', rule, { | ||
valid: [ | ||
'expect(callback).toWarnDev("warning");', | ||
'expect(function() { expect(callback).toThrow("error") }).toWarnDev("warning");', | ||
], | ||
invalid: [ | ||
{ | ||
code: | ||
'expect(function() { expect(callback).toWarnDev("warning") }).toThrow("error");', | ||
errors: [ | ||
{ | ||
message: 'toWarnDev() matcher should not be nested', | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
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
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,33 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function(context) { | ||
return { | ||
Identifier(node) { | ||
if (node.name === 'toWarnDev') { | ||
let current = node; | ||
while (current.parent) { | ||
if (current.type === 'CallExpression') { | ||
if ( | ||
current && | ||
current.callee && | ||
current.callee.property && | ||
current.callee.property.name === 'toThrow' | ||
) { | ||
context.report(node, 'toWarnDev() matcher should not be nested'); | ||
} | ||
} | ||
current = current.parent; | ||
} | ||
} | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.