import { render, screen, waitFor } from '@testing-library/react';
import { rest } from 'msw';
import News from '../News';
import { server } from '../../../mocks/server';
describe('<Users />', () => {
test('should component show error message', async () => {
server.resetHandlers(
rest.get('http://localhost:5000/news', (req, res, ctx) => {
return res(ctx.status(400));
})
);
render(<News />);
await waitFor(async () => {
const error = await screen.findByText(/SERVER ERROR/i);
expect(error).toBeInTheDocument();
});
});
});
我们可以使用waitFor的方式等待所有非同步事件完成并触发callback,解释如下
waitFor
may run the callback a number of times until the timeout is reached. Note that the number of calls is constrained by the timeout
and interval
options.
This can be useful if you have a unit test that mocks API calls and you need to wait for your mock promises to all resolve.
二元树走访或称二元树遍历,简单来说就是走访树中各节点,转化为线性关系。 主要分成两种策略方式 深度优...
Practice Quest-Integrate with Machine Learning API...
一、前言 想要进行资料分析,要做的第一件事当然是收集资料,所幸现在是2021,我们不需要为了股票资料...
跨站脚本攻击(XSS) 攻击 XXS就是透过网页没有适当筛选、处理文字造成的漏洞 例如有用户将<...
使用 mv 来更改档案名称 mv test1.txt test2.txt 使用 mv 来移动整个资料...