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

[test] Improve tests related to lists #13517

Merged
merged 2 commits into from
Nov 5, 2018

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Nov 5, 2018

Followup on #13498

The general idea is to move away from explicit child traversal to a more component tree agnostic approach. We can always argue what the actual implementation detail is (component tree or DOM tree) but I read the test as "ok if I pass component="li" I want the li DOM element" so that's what we're testing. As far as I'm concerned nobody cares how the component tree looks and every time we add/remove a wrapper component that just handles logic we break our unit tests.

For this purpose I introduced a findOutermostIntrinsic helper. It works similar to ReactWrapper#getDOMNode but returns an actual ReactWrapper. I thought about using find('*').first() since #find is top-down but the universal selector is not implemented (enzymejs/enzyme#1158) and might select any component if implemented and not just "DOM components".

Intrinsic is something I picked up from the way TypeScript handles react: https://www.typescriptlang.org/docs/handbook/jsx.html

@eps1lon eps1lon added test component: list This is the name of the generic UI component, not the React module! labels Nov 5, 2018
});

it('should change the component', () => {
const wrapper = mount(<ListItem button component="li" />);
const listItem = wrapper.find(MergeListContext).childAt(0);
assert.strictEqual(listItem.props().component, 'li');
assert.strictEqual(wrapper.find(ButtonBase).props().component, 'li');
Copy link
Member

Choose a reason for hiding this comment

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

Why not using findOutermostIntrinsic everywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. First iteration didn't have that method. Only came up with it after the initial rewrite.

Copy link
Member Author

Choose a reason for hiding this comment

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

Used getDOMNode since that is closer to what we want to test. The new helper is really only if you want to chain other enzyme methods on it.

@oliviertassinari oliviertassinari merged commit 9916d79 into mui:master Nov 5, 2018
@oliviertassinari
Copy link
Member

@eps1lon well done! :)

@eps1lon eps1lon deleted the test/List/improve-robustness branch September 14, 2021 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: list This is the name of the generic UI component, not the React module! test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants