React,Jest-无法一起运行测试

时间:2020-09-25 08:10:18

标签: reactjs jestjs react-testing-library

我正在使用此库:

  • 反应16.12.0
  • 开玩笑26.4.0
  • 反应测试库11.0.4
  • react-testing-library / jest-dom 5.11.4

我有这个测试:

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)

0 个答案:

没有答案