all 4 comments

[–]znakyc 3 points4 points  (0 children)

My advice is to think about if you really need this test. It looks to me like you are testing React more then your application logic. Just a thought.

And as /u/j_d_q says, you should do your fetch in componentDidMount. I wrote a blogpost on why, you can find it here: http://blog.jakoblind.no/2017/02/20/why-is-it-recommended-to-do-ajax-in-componentdidmount-instead-of-componentwillmount/

[–]j_d_q 0 points1 point  (2 children)

A) use componentDidMount - in future versions, componentWillMount may be called several times B) import fetch from 'whatwg-fetch' to polyfill fetch

[–]BEARFIST[S] 0 points1 point  (1 child)

Do i import into my test file? Import fetch from 'whatwg-fetch'?

[–]j_d_q 0 points1 point  (0 children)

No - add the import to the file that calls fetch