expect

http.expect([method], [url], [count])

The expect method works like calling http.when except it tracks the amount of calls to that address. You can then assert that the request has been made using http.assert.

The returned object is the same as http.when so you can still specify a return value etc.

test('it sends a specific ajax request', t => {
  http.expect('get', '/api/path/1').return({status : 200});
  service.doSomething();
});

test.afterEach(t => {
  t.notThrows(http.assert());
});

You can also specify a count. This means that a request must be sent a specific number of times.

http.expect('post', '/api/path/1', 3); // must post to /api/path/1 exactly 3 times
http.expect('delete', /.*/, 0); // must NOT send a delete request

The assert method throws an error if the request has not been sent, or has not been sent the expected number of times. It will also clear the list of expected requests.

results matching ""

    No results matching ""