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

Switch away from using enzyme.mount in tests (viewport/test/with-viewport-match.js) #7828

Conversation

nerrad
Copy link
Contributor

@nerrad nerrad commented Jul 9, 2018

Description

This switches all tests in viewport/test/with-viewport-match.js from using enzyme.mount to React.TestUtils. This is because enzyme does not fully support React 16.3+ (and movement to do so is really slow). This will fix issues with breakage due to the enzyme incompatibility as components receive React 16.3+ features (such as forwardRef usage in #7557).

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

This switches all tests in `viewport/test/with-viewport-match.js` from using enzyme.mount to `React.TestUtils`.  This is because `enzyme` does not fully support React 16.3+ (and movement to do so is really slow). This will fix issues with breakage due to the enzyme incompatibility as components receive React 16.3+ features (such as `forwardRef` usage in #7557).
@nerrad nerrad requested a review from aduth July 9, 2018 14:53
@nerrad nerrad self-assigned this Jul 9, 2018
@nerrad nerrad added [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Refactoring labels Jul 9, 2018

expect( wrapper.find( Component ).props() ).toEqual( { isWide: true } );
expect( wrapper.root.findByType( ChildComponent ).props.isWide )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't exactly the same check. Can we update it to make sure it doesn't change anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry I'm not sure exactly what you mean by "Can we update it to make sure it doesn't change anything?". I'm also not sure why you think this isn't the same check. I had to wrap ChildComponent in the TestComponent so effectively I'm doing the same test, just doing a different method for getting the component to test. This same method will apply when HOCs are returning a forwardRef wrapped component (in 7557).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another alternative here would be to use TestUtils to do a full mount into the DOM and then traverse actual HTMLElement nodes to verify expected results? But I'm not sure that is any better than what is happening here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect( wrapper.root.findByType( ChildComponent ).props ).toEqual( { isWide: true });

This is what I thought about. Does ref causes any issues here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ensured these tests passed against 7557 (while preserving the intent of the test). Then ensured the same tests passed against master (if they didn't pass against master then I knew there was a problem).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's minor, we can skip it :)

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@gziolo gziolo merged commit 7ba7a59 into master Jul 12, 2018
@gziolo gziolo deleted the update/with-viewport-match.js-replace-usage-of-enzyme.mount-with-React.TestRenderer branch July 12, 2018 13:08
@gziolo gziolo added this to the 3.3 milestone Jul 12, 2018
@ellatrix ellatrix added [Type] Code Quality Issues or PRs that relate to code quality and removed [Type] Code Quality Issues or PRs that relate to code quality labels Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants