-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toHaveClass should wrap existing matcher #1
Comments
Hey @jcarlson! Sorry things are breaking. You're right, it should check for an existing method before registering a new one. What type of value is |
My matchers are expecting a node and a string to assert that the node has that class. Such as: class MyComponent extends Component {
render () {
return <div className='my-component'>Hello!</div>
}
}
let rendered = ReactDOM.render(<MyComponent />, document.createElement('div'))
let node = ReactDOM.findDOMNode(rendered)
expect(node).toHaveClass('my-component') Here's my matchers: expect.extend({
toHaveClass (className) {
expect.assert(
this.actual.classList ?
this.actual.classList.contains(className) :
false,
'Expected class list %s to contain %s.',
this.actual.classList ?
Array.from(this.actual.classList) :
'(not a DOM element)',
className
)
return this
},
toNotHaveClass (className) {
expect.assert(
this.actual.classList ?
!this.actual.classList.contains(className) :
true,
'Expected class list %s to not contain %s.',
this.actual.classList ?
Array.from(this.actual.classList) :
'(not a DOM element)',
className
)
return this
}
}) |
Sweet, thanks! |
If a user of this library already has custom assertions of the same name, previously, this library would completely overwrite them. Now it Attempts to wrap the existing method, falling back if `actual` is not an enzyme wrapper. If the built-in doesn't exist, the previous behavior is kept (assert actual is enzyme). Please refer to issue #1 for more details.
I've just pushed out |
My test suite already has a custom matcher called
toHaveClass
(and alsotoNotHaveClass
). Soexpect-enzyme
clashes with this existing matcher and breaks tests which are expecting the non-enzymified version of the matcher.Looks like it should be trivial to
addEnzymeSupport
to resolve this...The text was updated successfully, but these errors were encountered: