反应组件测试中的玩笑超时

时间:2019-07-13 06:38:25

标签: reactjs fetch react-testing-library fetch-mock

我收到开玩笑的超时错误。猜测fetch-mock调用尚未完成。我应该做些不同的事情吗?

--componentDidMount
getResponse({serviceUrl})
    .then((result) => {
        if (result.status !== 'error') {
            this.setState({
                data: result.response,
                isLoading: false
            });
        }
    });


-- getReponse = (props) => {
return poll({ response: {}, url }); }

--poll method 
const poll = ({ response, url }) => {
if (response.status === 'success' || response.status === 'error') {
    return response;
}
return fetch(url)
    .then((a) => a.json())
    .then((response) =>
        delay(1000).then(() => poll({ response, url })));
};

--Test case
jest.useFakeTimers();
test('should display Table', async (done) => {
    fetchMock.get('*', respJson);
    const { container, getByText,} = render(<App {...props}/>);
    jest.runAllTimers();
    const tableIcon = await waitForElement(() => getByText('Table'));
    expect(container).toContainElement(tableIcon);
    done();
});

任何输入将不胜感激。

0 个答案:

没有答案