mercredi 15 juillet 2020

Multiple Time Method Call while testing an async Function in JavaScript

Why i have to call await asyncMock() twice?

test('async test', async () => {
  const asyncMock = jest
    .fn()
    .mockResolvedValueOnce('first call')
    .mockRejectedValueOnce(new Error('Async error'));

  await asyncMock(); // first call
  await asyncMock(); // throws "Async error"
});

This code snippet is taken from jest documentation

Aucun commentaire:

Enregistrer un commentaire