lundi 25 avril 2016

Testing React output after a delay (using Tape)

Here is my test code:

Dispatcher.emit('api:data:foo', fooPayload)
t.true(result.find('.foo').text() == 'Foo bar', 'Foo is set')

Dispatcher is an Event Emitter. The React component I'm testing is using this Event Emitter to respond to events and re-render/update accordingly. However, as there are quite a lot of updates, I throttle the actual setting of the state (in the React component) to 200ms. This is causing an issue in my test because it's obviously checking the rendered output immediately after it's emitted the event. I could wrap my test check in a setTimeout, but that feels awful.

Is there an elegant way of dealing with this issue?

I'm using Tape

Aucun commentaire:

Enregistrer un commentaire