From 77659f7a89e8dfb254415ea02b999ddbf4ff24b8 Mon Sep 17 00:00:00 2001 From: Brandon Carroll Date: Sun, 7 Apr 2019 22:34:32 -0400 Subject: [PATCH] fix: make toHaveTextContent() handle arrays and strings better --- src/to-have-text-content.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/to-have-text-content.js b/src/to-have-text-content.js index 1ebe7bf..97a6ced 100644 --- a/src/to-have-text-content.js +++ b/src/to-have-text-content.js @@ -1,5 +1,5 @@ import { matcherHint } from 'jest-matcher-utils'; -import { compose, defaultTo, join, map, path } from 'ramda'; +import { compose, defaultTo, is, join, map, path } from 'ramda'; import { checkReactElement, getMessage, matches, normalize } from './utils'; @@ -27,7 +27,7 @@ export function toHaveTextContent(element, checkWith) { // step 5: map the array to get text content map(child => (typeof child === 'object' ? getText(child) : child)), // step 4: make sure non-array children end up in an array - Array.from, + child => (is(Array, child) ? child : [child]), // step 3: default to an array defaultTo([]), // step 2: drill down to the children