mirror of
https://github.com/facebook/react-native.git
synced 2024-11-21 21:27:46 +00:00
Implement toThrow(message) with a specific error message string (#47700)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47700 Changelog: [internal] Add support for the string parameter for `toThrow` to assert for specific error messages. Reviewed By: sammy-SC Differential Revision: D66118001 fbshipit-source-id: 8c04cd20d4ad17163ec0c7bf943c429507a97985
This commit is contained in:
parent
47882f0000
commit
05874c831b
@ -215,17 +215,19 @@ class Expect {
|
||||
}
|
||||
}
|
||||
|
||||
toThrow(error: mixed): void {
|
||||
if (error != null) {
|
||||
throw new Error('toThrow() implementation does not accept arguments.');
|
||||
toThrow(expected?: string): void {
|
||||
if (expected != null && typeof expected !== 'string') {
|
||||
throw new Error(
|
||||
'toThrow() implementation only accepts strings as arguments.',
|
||||
);
|
||||
}
|
||||
|
||||
let pass = false;
|
||||
try {
|
||||
// $FlowExpectedError[not-a-function]
|
||||
this.#received();
|
||||
} catch {
|
||||
pass = true;
|
||||
} catch (error) {
|
||||
pass = expected != null ? error.message === expected : true;
|
||||
}
|
||||
if (!this.#isExpectedResult(pass)) {
|
||||
throw new Error(
|
||||
|
Loading…
Reference in New Issue
Block a user