From 8b25296bd9cb396ac220bb40b5b16f1bf34970ee Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Sat, 26 Jan 2019 13:11:36 -0500 Subject: [PATCH] expect: Make change requested in toThrowMatchers --- packages/expect/src/toThrowMatchers.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/expect/src/toThrowMatchers.js b/packages/expect/src/toThrowMatchers.js index 1f2aa67aa3f5..a53e6979e461 100644 --- a/packages/expect/src/toThrowMatchers.js +++ b/packages/expect/src/toThrowMatchers.js @@ -38,28 +38,22 @@ type Thrown = }; const getThrown = (e: any): Thrown => { - if ( - e !== null && - e !== undefined && - typeof e.message === 'string' && - typeof e.name === 'string' && - typeof e.stack === 'string' - ) { + const hasMessage = + e !== null && e !== undefined && typeof e.message === 'string'; + + if (hasMessage && typeof e.name === 'string' && typeof e.stack === 'string') { return { - hasMessage: true, + hasMessage, isError: true, message: e.message, value: e, }; } - const hasMessage = - e !== null && e !== undefined && typeof e.message === 'string'; - return { hasMessage, isError: false, - message: hasMessage ? e.message : typeof e === 'string' ? e : String(e), + message: hasMessage ? e.message : String(e), value: e, }; };