Testing API with axios - getting triggerUncaughtException(err, true /* fromPromise */);

1k Views Asked by At
function signup(data_var) {
  const options = {
    method: 'POST',
    url: 'xxx',
    headers: {
      'Content-Type': 'application/json',
      Authorization: 'Bearer undefined',
    },
    data: data_var,
  };
  return axios
    .request(options)
    .then(function (response) {
      return response;

    })
    .catch(function (error) {
      return error;
    });
}

it('should return 200 status code', async () => {
  var random = Math.floor(Math.random() * 1000000);
  var email = 'shadow' + random + '@gmail.com';

  signup({

    firstName: 'test',
    lastName: 'testing',
    email: email,
  })
    .then(function (response) {
      expect(response.status)
        .toBe(200);
    });
});

It will create a new user but when I check status code 200 it throws this error

Error Message

> node:internal/process/promises:245 triggerUncaughtException(err, true /* fromPromise */); Expected: 200

Received: undefined".] { code: 'ERR_UNHANDLED_REJECTION' }

0

There are 0 best solutions below