我有一个功能组件,我试图测试,似乎有一些问题,围绕端点调用通过axios。
const url = user.myUrl + "/someEndpoint";
const RESPONSE = await axios.post(url);
console.log("RESPONSE ::::::::::::::::::::::::" + RESPONSE);
试验如下:
test("Validate something", async () => {
const {container} = render(
<MyComponent url={url} />
);
expect(await container.getElementsByClassName('someGrid').length).toBe(2);
});
当我运行测试时,我得到了下面的错误;
Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "RESPONSE ::::::::::::::::::::::::[object Object]".
PS:我正在通过MSW模拟端点。
1条答案
按热度按时间fnvucqvd1#
由于
MyComponent
在其中有一个影响,即axios POST,您需要等待结果。(You'如果您尚未使用
waitFor
,则很可能需要导入它)