有什么方法可以在内部使用自定义查询吗?自定义查询适用于使用适配器模块的渲染功能:
import { render, queries } from '@testing-library/react';
import * as customQueries from './custom-queries';
const customRender = (ui, options) =>
render(ui, { queries: { ...queries, ...customQueries }, ...options });
// re-export everything
export * from '@testing-library/react';
// override render method
export { customRender as render };
但是当我使用 inside 时,它看不到我的自定义查询,这通常是预期的。有什么方法可以使用自定义查询扩展 within
吗?
最佳答案
就像您拥有 customRender
一样,您也可以拥有 customWithin
:
const customWithin = (element) => within(element, { ...queries,...customQueries });
关于react-testing-library - React 测试库与自定义查询一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60477298/