Skip to content

Commit

Permalink
enzyme components must exist
Browse files Browse the repository at this point in the history
  • Loading branch information
MicheleBertoli committed Aug 22, 2018
1 parent cbd755f commit 39925fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/toHaveStyleRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getClassNames = received => {
if (received) {
if (received.$$typeof === Symbol.for('react.test.json')) {
className = received.props.className || received.props.class
} else if (typeof received.findWhere === 'function') {
} else if (typeof received.exists === 'function' && received.exists()) {
const tree = shouldDive(received) ? received.dive() : received
const components = tree.findWhere(isTagWithClassName)
if (components.length) {
Expand Down
2 changes: 2 additions & 0 deletions test/__snapshots__/toHaveStyleRule.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ Expected
Received:
\\"background: orange\\""
`;

exports[`non existing 1`] = `"No style rules found on passed Component"`;
14 changes: 14 additions & 0 deletions test/toHaveStyleRule.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ test('message when value does not match', () => {
}).toThrowErrorMatchingSnapshot()
})

test('non existing', () => {
const Wrapper = styled.section`
padding: 4em;
background: papayawhip;
`

expect(() => {
expect(shallow(<Wrapper />).find('div')).toHaveStyleRule(
'background',
'papayawhip'
)
}).toThrowErrorMatchingSnapshot()
})

test('basic', () => {
const Wrapper = styled.section`
padding: 4em;
Expand Down

0 comments on commit 39925fc

Please sign in to comment.