From 5965a385d5e2d547c2accdff28e76f5677ddb3e2 Mon Sep 17 00:00:00 2001 From: Michele Bertoli Date: Sun, 22 Oct 2017 10:56:50 +0100 Subject: [PATCH] support complex trees --- src/toHaveStyleRule.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/toHaveStyleRule.js b/src/toHaveStyleRule.js index 161df42..a776baa 100644 --- a/src/toHaveStyleRule.js +++ b/src/toHaveStyleRule.js @@ -1,7 +1,10 @@ const { getCSS } = require('./utils') const shouldDive = node => - typeof node.type() !== 'string' && 'innerRef' in node.props() + typeof node.dive === 'function' && typeof node.type() !== 'string' + +const isTagWithClassName = node => + node.prop('className') && typeof node.type() === 'string' const getClassNames = received => { let className @@ -9,11 +12,11 @@ const getClassNames = received => { if (received) { if (received.$$typeof === Symbol.for('react.test.json')) { className = received.props.className - } else if (typeof received.find === 'function') { + } else if (typeof received.findWhere === 'function') { const tree = shouldDive(received) ? received.dive() : received - const components = tree.find('[className]') + const components = tree.findWhere(isTagWithClassName) if (components.length) { - className = components.last().prop('className') + className = components.first().prop('className') } } }