jeudi 24 août 2017

How to test asynchronous components

I would like to write some tests for the components that work with data fetching. For example, I need to test this logic:

  1. User click on the button "add image".
  2. A modal window appears and sends a request to get user images. When the request is done - the component shows user images.
  3. User selects one image and click the button "select"
  4. Component should return selected image

To test any part of this logic, I need to w8 after the request is done. How can I do this?

I try to use axios-mock-adapter, moxios, sinon-as-promised, sinon.fakeServer but no one works for me. I can attach my current implementation of this thing here if needed.

P.S. I know that I can break up my test and assay each part. But this is what makes my tests very fragile, just because each time when implementation changes all tests should be rewritten. That's why I start writing tests only for UI but not for implementations

Aucun commentaire:

Enregistrer un commentaire