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);
});
});
它将创建一个新用户,但是当我检查状态代码 200 时,它会抛出此错误
错误信息
> node:internal/process/promises:245 triggerUncaughtException(err, true /* fromPromise */); 预计:200
收到:未定义”。] {代码:'ERR_UNHANDLED_REJECTION'}