Closed SevInf closed 4 years ago
I think you want to use toContainReact
expect(wrapper).toContainReact(<DummyComponent />)
I'm going to close, but let me know if this doesn't solve your needs and we can dive into this more. Absolutely want to make sure you get the help you need :)
@blainekasten
Although the provided example indeed solves that specific use-case, the fact that the assertions use enzyme.find under the hood, does provide additional flexibility when writing tests:
// Assert the number of instances of certain component
expect(wrapper).toContainMatchingElements(3, DummyComponent);
// Assert any component with certain prop
expect(wrapper).toContainMatchingElements({someProp: 'someValue'});
Although the documentation does not really cover such use-cases, they are extremely useful when writing tests and I'd really vouch for not cutting users out from such treats as soon as they use typing argument typing.
It would just require copying over the overloads from enzyme find.
This is a valid code in JS:
However, typescript rejects it:
Enzyme's own type definitions contain a much more flexible signature for selectors, where
jest-enzyme
defines only string selectors.One possible workaround is rewriting original assertion to:
but would be nice if the original code was accepted as is.