Skip to content

Enzyme (React Component Unit-Testing)#344

Closed
jrodl3r wants to merge 23 commits intoreactGo:masterfrom
jrodl3r:enzyme-testing
Closed

Enzyme (React Component Unit-Testing)#344
jrodl3r wants to merge 23 commits intoreactGo:masterfrom
jrodl3r:enzyme-testing

Conversation

@jrodl3r
Copy link
Member

@jrodl3r jrodl3r commented Jul 16, 2016

Re: #261

describe('<MainSection />', () => {
describe('With Topics', () => {
it('should render <TopicItem> list items', () => {
expect(mount(<MainSection topics={topicItemData} {...stubFunctions} />).find('.list li').length).toBe(1);
Copy link
Member

@choonkending choonkending Jul 21, 2016

Choose a reason for hiding this comment

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

Minor comment: should this be find(TopicItem) given that we are asserting that MainSection contains TopicItem?

expect(wrapper.find(Foo)).to.have.length(3);

Finding .list li works, but that ties this test to the specific implementation of TopicItem, i.e. if at some point in the future, we change TopicItem to be <div>, this test will break even though it shouldn't. :)

(Sorry if I'm being really critical with this test, but given that this is the first of the enzyme tests, I'm really trying my best to ensure it will be awesome for everyone!)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, Enzyme has very flexible/expressive selectors. Do you have any suggestions for the choice to go with here? Also, is there any documentation that you would like me to add/update? Thx 👍

Copy link
Member

Choose a reason for hiding this comment

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

I'd still go with find , the way you did it, following this doc here in enzyme.

so instead of using .list li

I would

expect(mount(<MainSection topics={topicItemData} {...stubFunctions} />).find(TopicItem).length).toBe(1);

is there any documentation that you would like me to add/update?

So far we don't have any docs for testing yet, but I think we should outline good testing practices here as a doc after this gets merged in.

Thanks!

@choonkending
Copy link
Member

@jrodl3r Excellent changes - and thanks for pushing this through!

@jrodl3r
Copy link
Member Author

jrodl3r commented Jul 27, 2016

Moved to #384

@jrodl3r jrodl3r closed this Jul 27, 2016
@jrodl3r jrodl3r deleted the enzyme-testing branch July 27, 2016 18:56
@jrodl3r jrodl3r restored the enzyme-testing branch July 27, 2016 18:56
@jrodl3r jrodl3r deleted the enzyme-testing branch July 27, 2016 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants