Skip to content

Commit c86b3be

Browse files
committed
fix contain and containMatchingElement to accept string values
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.
1 parent 5352ff5 commit c86b3be

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/reactNodeToString.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ function reactArrayToJSXString (nodes) {
2020
export default function reactNodeToString (node) {
2121
if (Array.isArray(node)) {
2222
return reactArrayToJSXString(node)
23+
} else if (typeof node !== 'object') {
24+
return String(node)
2325
} else {
2426
return reactElementToJSXString(node)
2527
}

test/contain.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Fixture extends React.Component {
2222
<User index={2} />
2323
<User index={3} />
2424
</li>
25+
<li>Unknown User</li>
2526
</ul>
2627
</div>
2728
)
@@ -35,6 +36,7 @@ describe('#contain', () => {
3536
it('passes when the actual matches the expected', (wrapper) => {
3637
expect(wrapper).to.contain(<User index={1} />)
3738
expect(wrapper).to.contain(<User index={2} />)
39+
expect(wrapper).to.contain('Unknown User')
3840
}, { render: false })
3941

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

test/containMatchingElement.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Fixture extends React.Component {
2020
<ul>
2121
<li><User index={1} name='John' /></li>
2222
<li><User index={2} name='Doe' /></li>
23+
<li>Unknown User</li>
2324
</ul>
2425
</div>
2526
)
@@ -33,6 +34,7 @@ describe('#containMatchingElement', () => {
3334
it('passes when the actual matches the expected', (wrapper) => {
3435
expect(wrapper).to.containMatchingElement(<User name='John' />)
3536
expect(wrapper).to.containMatchingElement(<User name='Doe' />)
37+
expect(wrapper).to.containMatchingElement('Unknown User')
3638
}, { render: false })
3739

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

0 commit comments

Comments
 (0)