expect

store.expect([method], [name], [count])

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

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

test('it dispatches an event', t => {
  store.expect('dispatch', 'updateUser').return('success');
  service.doSomething();
});

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

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

store.expect('commit', 'DO_SOMETHING', 3);
store.expect('dispatch', /.*/, 0); // must NOT receive any dispatches

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 ""