如何解决如何在React Fetching Library中模拟上下文?
大家好,我在模拟react fetching library function useQuery以通过容器组件中的api读取数据的测试方面遇到问题。现在我有一个错误,无法在dom中找到模拟标签。在控制台中,它仍然输出,只有加载程序可见。 我不知道如何等待加载指示灯消失。
我有以下错误:
Unable to find an element with the
text: #1. This could be because the text is broken up by multiple elements.
In this case,you can provide a function for your text matcher to make your matcher more flexible.
这是容器组件测试
import React from 'react';
import { getByTestId } from '@testing-library/react';
import { ClientContextProvider } from 'react-fetching-library';
import { render,act } from 'tests';
import tags from 'api/mocks/tags-response.json';
import { TrendingTagsContainer } from './TrendingTagsContainer';
describe('TrendingTagsContainer component',() => {
const client = {
query: async () => ({
error: false,status: 200,payload: tags,}),suspenseCache: false,};
test('should render component with correct title and description',async () => {
jest.useFakeTimers();
const { getByText,container } = render(
<ClientContextProvider client={client}>
<TrendingTagsContainer />
</ClientContextProvider>,);
expect(getByTestId(container,'loader')).toBeInTheDocument();
act(() => {
jest.runAllTimers();
});
expect(getByText('#1')).toBeInTheDocument();
});
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。