The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Will Gilbert (5) [Avatar] Offline
#1
The helper method 'getElement' is returning too many elements e.g as many elements as it is nested:

  const getElement = wrapper => elementType => classToSearchFor => (
  wrapper.find(elementType).findWhere(e => e.props().className && e.props().className.indexOf(classToSearchFor) !== -1)
);


However, changing to this seems to works and maintains the intent of the method:

const getElement = wrapper => elementType => classToSearchFor => (
  wrapper.find(elementType).filterWhere(n => n.hasClass(classToSearchFor))
);
Zac Braddy (8) [Avatar] Offline
#2
Hi Will

Thanks for the feedback mate, that is most odd. May I ask, does this behaviour happen when you're using a branch from the courses github repo without any changes to it or are you following along with your own codebase? If it is a branch which one are you seeing this in? If you are following along with your own code base would you care to share the code for the component that you're seeing this behaviour in?

Just interested to see if I can diagnose the problem you're having, even if that problem might simply be that I made a goof smilie

Cheers
Zac
Will Gilbert (5) [Avatar] Offline
#3
Currently working in branch 'u5-m3-doit'. As is, 'getElement' returns all nested matching elements; When I swap in the shorter version which I posted above all tests pass because a single element is returned.

BTW -- I love the way you use TDD. It was extremely helpful in learning how to do it in JavaScript & React. Have used TDD for years as a Java programmer.
628182 (1) [Avatar] Offline
#4
Thanks a lot Will Gilbert, now it works for me too

It was really confusing cause the img test passed and then you get 3 nodes instead of 1.

Then i checked the master version for help but there was no getElement in there

This should be fixed!!!!!!!!!!!!!

I also loved the TDD aproach, but using enzyme may be an overkill for am introductory course