Skip to content

Commit

Permalink
fix contain and containMatchingElement to accept string values
Browse files Browse the repository at this point in the history
before, a string was accepted via react-element-to-jsx-string.
As that is no longer being used in favor of a custom function,
a string should still be accepted.
  • Loading branch information
brucewpaul committed Oct 11, 2017
1 parent 5352ff5 commit 71f587a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/reactNodeToString.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function reactArrayToJSXString (nodes) {
export default function reactNodeToString (node) {
if (Array.isArray(node)) {
return reactArrayToJSXString(node)
} else if (typeof node === 'string') {
return node
} else {
return reactElementToJSXString(node)
}
Expand Down
2 changes: 2 additions & 0 deletions test/contain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Fixture extends React.Component {
<User index={2} />
<User index={3} />
</li>
<li>Unknown User</li>
</ul>
</div>
)
Expand All @@ -35,6 +36,7 @@ describe('#contain', () => {
it('passes when the actual matches the expected', (wrapper) => {
expect(wrapper).to.contain(<User index={1} />)
expect(wrapper).to.contain(<User index={2} />)
expect(wrapper).to.contain('Unknown User')
}, { render: false })

it('passes negated when the actual does not match the expected', (wrapper) => {
Expand Down
2 changes: 2 additions & 0 deletions test/containMatchingElement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Fixture extends React.Component {
<ul>
<li><User index={1} name='John' /></li>
<li><User index={2} name='Doe' /></li>
<li>Unknown User</li>
</ul>
</div>
)
Expand All @@ -33,6 +34,7 @@ describe('#containMatchingElement', () => {
it('passes when the actual matches the expected', (wrapper) => {
expect(wrapper).to.containMatchingElement(<User name='John' />)
expect(wrapper).to.containMatchingElement(<User name='Doe' />)
expect(wrapper).to.containMatchingElement('Unknown User')
}, { render: false })

it('passes negated when the actual does not match the expected', (wrapper) => {
Expand Down

0 comments on commit 71f587a

Please sign in to comment.