-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for containMatchingElement (#149)
* add support for containsMatchingElement * Update documentation, rename helper * fix typo in README.md * remove IDE Settings from repo * set changes in CHANGELOG.md to unreleased * add notice for breaking change in CHANGELOG.md
- Loading branch information
1 parent
cedba77
commit 74e4b16
Showing
7 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/node_modules/ | ||
/build/ | ||
*.local.js | ||
npm-debug.log* | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import reactElementToJSXString from 'react-element-to-jsx-string' | ||
|
||
export default function containMatchingElement ({ wrapper, markup, arg1, sig }) { | ||
const arg1JSXString = reactElementToJSXString(arg1) | ||
|
||
this.assert( | ||
wrapper.wrapper.containsMatchingElement(arg1), | ||
() => 'expected ' + sig + ' to contain matching ' + arg1JSXString + markup(), | ||
() => 'expected ' + sig + ' not to contain matching ' + arg1JSXString + markup(), | ||
arg1 | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
class User extends React.Component { | ||
render () { | ||
return ( | ||
<span>User {this.props.index} {this.props.name}</span> | ||
) | ||
} | ||
} | ||
|
||
User.propTypes = { | ||
index: React.PropTypes.number, | ||
name: React.PropTypes.string.isRequired | ||
} | ||
|
||
class Fixture extends React.Component { | ||
render () { | ||
return ( | ||
<div> | ||
<ul> | ||
<li><User index={1} name='John' /></li> | ||
<li><User index={2} name='Doe' /></li> | ||
</ul> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
const it = createTest(<Fixture />) | ||
|
||
describe('#containMatchingElement', () => { | ||
describe('(node)', () => { | ||
it('passes when the actual matches the expected', (wrapper) => { | ||
expect(wrapper).to.containMatchingElement(<User name='John' />) | ||
expect(wrapper).to.containMatchingElement(<User name='Doe' />) | ||
}, { render: false }) | ||
|
||
it('passes negated when the actual does not match the expected', (wrapper) => { | ||
expect(wrapper).to.not.containMatchingElement(<User name='Conor' />) | ||
}, { render: false }) | ||
|
||
it('fails when the actual does not match the expected', (wrapper) => { | ||
expect(() => { | ||
expect(wrapper).to.containMatchingElement(<User name='Conor' />) | ||
}).to.throw('to contain matching <User name="Conor" />') | ||
|
||
expect(() => { | ||
expect(wrapper).to.not.containMatchingElement(<User name='Doe' />) | ||
}).to.throw('not to contain matching <User name="Doe" />') | ||
}, { render: false }) | ||
|
||
it('fails when the actual is undefined', () => { | ||
expect(() => { | ||
expect(undefined).to.containMatchingElement(<User name='John' />) | ||
}).to.throw() | ||
}) | ||
}) | ||
}) |