mardi 6 juin 2017

Consecutive asynchronous test steps in ava

The problem

The popular ava package features a simple and powerful testing framework for javascript:

import test from 'ava';

test('single step', t => {
    t.is('bar', 'bar');
    t.end();
});

Testing is dead simple for synchronous code. However, I am not sure how to write tests with multiple, consecutive, dependent steps.

For example, I would like to test a REST API. I would like to create a resource using POST, make sure it exists with GET call, and delete it with DELETE.

Needless to say, the order matters: the POST call must be finished before the GET call can start, and sometimes we even want a sleep time between steps.

What have I tried

  • Tried a series of setTimeouts where where the callback of each call is the next test step. It is fairly unreadable.

My question

What's the right way to write a test with multiple consecutive steps with ava?

These steps are asynchronous and consecutive

Aucun commentaire:

Enregistrer un commentaire