-
Notifications
You must be signed in to change notification settings - Fork 19
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
Support lifecycle methods #46
Comments
There are patterns to do this with unexpected-react now.
You can render the component yourself (without using `when [deeply]
rendered`), then render the component again as you said with new props.
Then use the renderer or component instance in the assertion.
```js
const renderer = TestUtils.createRenderer()
renderer.render(<MyComponent prop="first" />)
renderer.render(<MyComponent prop="second" />)
expect(renderer, 'to have rendered', ...)
```
We can try and add this new assertion, as I think it would be quite useful
as it means you can use the `when rendered` and similar assertions, but
just wanted to point out it can be done :)
…On Tue, 1 Aug 2017, 22:50 Albert Fernández, ***@***.***> wrote:
Hi!
I have some piece of code I'd like to test, however it's on
componentWillReceiveProps. Currently, there doesn't seem to be a way to
test this using unexpected-react.
A solution is to re-render the same component on the same DOM node, which
React will re-render instead of remount. Example
<https://stackoverflow.com/a/30616091/1794589>
I think adding this assertion could probably do the job:
<RenderedReactElement> when receiving new props <object> <assertion>
What do you think? Thanks!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#46>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AAFmRGO7xy0z4jpU7xafKkGivP3exjOPks5sT4-ggaJpZM4OqRsz>
.
|
Nice, I didn't know it was as easy. The example I pointed was a lot more boilerplate. I think it would be quite useful to add, testing these re-render lifecycles should have first-level support. Happy to add to do a PR for this if you can point me a bit on where to start. Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
I have some piece of code I'd like to test, however it's on
componentWillReceiveProps
. Currently, there doesn't seem to be a way to test this usingunexpected-react
.A solution is to re-render the same component on the same DOM node, which React will re-render instead of remount. Example
I think adding this assertion could probably do the job:
<RenderedReactElement> when receiving new props <object> <assertion>
What do you think? Thanks!
The text was updated successfully, but these errors were encountered: