diff --git a/packages/jest-emotion/src/utils.js b/packages/jest-emotion/src/utils.js index 2ad1804bea..d093e3b629 100644 --- a/packages/jest-emotion/src/utils.js +++ b/packages/jest-emotion/src/utils.js @@ -8,7 +8,7 @@ function flatMap(arr, iteratee) { return [].concat(...arr.map(iteratee)) } -export function findLast(arr, predicate) { +export function findLast(arr: T[], predicate: T => boolean) { for (let i = arr.length - 1; i >= 0; i--) { if (predicate(arr[i])) { return arr[i] @@ -219,7 +219,11 @@ export function hasClassNames( // in the list of received node classNames to make sure this css rule // applied for root element if (!target) { - return classNames.includes(last(selector.split(' ')).slice(1)) + const lastCls = last(selector.split(' ')) + if (!lastCls) { + return false + } + return classNames.includes(lastCls).slice(1) } // check if selector (className) of specific css rule match target return target instanceof RegExp