我正在使用此库:
我有这个测试:
describe('Test suite', () => {
it('test1', async () => {
const config =
{
settings: {
...
}
};
const view = render(<MyApp config={config}/>);
const form = await screen.findByTestId(/form/i);
expect(form).toBeInTheDocument();
expect(view.asFragment()).toMatchSnapshot();
});
it('test2', async () => {
const config =
{
settings: {
...
}
};
const view = render(<MyApp config={config}/>);
const form = await screen.findByTestId(/form/i);
expect(form).toBeInTheDocument();
expect(view.asFragment()).toMatchSnapshot();
});
});
当我像单个测试运行一样运行 test1 和 test2 时,一切正常。但是,如果我运行测试套件,则 test1 没问题,并且 test2 失败,则导致配置对象未定义。有人可以帮我吗?
尝试:
afterEach(cleanup)