mercredi 20 janvier 2021

React jest test Promise inside Async

I have the below code but I can't seem to get it working. What am I doing wrong? Seems like the async wrapping the promise is causing the issue. No matter what I try I always get errors

export const doLogin = (email, password) => {
  return async (dispatch, getState) => {
    return new Promise((resolve, reject) => {
      resolve(true)
    })
  };
};

and the test using jest and enzyme

expect(await doLogin('', '')).resolves.toEqual(true);

the error i am getting is

    expect(received).resolves.toEqual()

    Matcher error: received value must be a promise

    Received has type:  function
    Received has value: [Function anonymous]

Aucun commentaire:

Enregistrer un commentaire