Skip to content
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

Use wrapper.getNode() instead of wrapper.node #27

Closed
jwbay opened this issue Nov 20, 2016 · 1 comment
Closed

Use wrapper.getNode() instead of wrapper.node #27

jwbay opened this issue Nov 20, 2016 · 1 comment

Comments

@jwbay
Copy link
Contributor

jwbay commented Nov 20, 2016

Enzyme recently picked up changes in v2.6.0 that remove the need for .update() in the shallow wrapper for a lot of cases. It accomplishes this by replacing the node and nodes properties with functions (getNode and getNodes) that always return the latest output of the underlying shallow renderer.

To keep back-compat with other versions of enzyme, one could simply check for .getNode and fall back to .node if it's not there.

Example:

const wrapper = shallow(<MyComponent />);
wrapper.find(Child).props().methodThatSetsStateOnMyComponent();
wrapper.update(); //shallow DOM won't be updated in the snapshot without this
expect(shallowToJson(wrapper)).toMatchSnapshot();

With the proposed change, we wouldn't need the .update() call.

@adriantoine
Copy link
Owner

Hi @jwbay, sorry for the delay, it looks interesting, are you interested in making a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants