使用jest和axiom编写API集成测试。我发誓,当我将承载令牌硬编码到put请求的头部时,我有一个简单的版本。但是在一些模糊之后,我甚至不能按ctrl + z到它"工作"的地方-我无法摆脱这个错误:
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● TLSWRAP
13 |
14 | it('user can create a cart', async () => {
> 15 | const response = await axios.put(
我已经尝试修复这些修复,但没有骰子。
- https://jestjs.io/docs/asynchronous
- Jest已检测到以下1个打开的句柄可能阻止Jest退出
我怎么能让它成功运行(200响应),而不是保释,因为打开句柄?
import axios from 'axios';
describe('Cart Manipulation', () => {
let oc_token: string;
beforeAll(() => {
oc_token = "eyJblahblahblah"
});
it('user can create a cart', async () => {
const response = await axios.put(
'https://api.urltogoto',
{
'Accept': 'application/json',
// 'Authorization': 'Bearer eyJblahblahblah'
'Authorization': oc_token
}
);
console.log(response);
expect(response.status).toBe(200);
});
});
找到了解决方案,我不知道具体是什么改变造成了差异,但大量的模糊产生了这个:
import axios, {AxiosRequestConfig} from 'axios';
describe('Cart Manipulation', () => {
it('user can create a cart', async () => {
let config = {
method: 'put',
maxBodyLength: Infinity,
url: 'https://api.blablahurl',
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer sillylittletoken'
}
} as AxiosRequestConfig;
const response = await axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
expect(response.status).toEqual(200);
})
.catch((error) => {
console.log(error);
});
});
});