





















Not sure if this is an issue, or whether I'm simply missing something. I'm using enzyme mount to test a top level connected component, which goes through multiple render cycles before the component is finally loaded (to fetch data, etc.).
For my testing environment I have overridden our ajax component to simply return JSON rather than making an external call for data. This seems to work; when I inspect the component after render, the store has the correct data.
We are using Jasmine and Karma. Here is the slimmest version of our test.
beforeEach((done) => {
cmp = mount(component);
setTimeout(() => {
done();
}, 12000);
});
it('should render a cmp', (done) => {
const x = cmp;
// at this point, x.component.findDOMNode() returns the dom node
// and the component is fully rendered, except that the component
// which reflects the data shows 0 record, but the store shows 2
done();
});
If I step through the render cycle of my component, the data is there, and it looks like it's returning a component which reflects the fetched data, however, the enzyme mount doesn't have that in the returned dom.
Perhaps this is a race condition, but as you can see I've set the timeout to 12000 which should be more than enough. Is there a better way to test a component that fetches data/ has multiple renders before we'd like to test it?
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。