有没有人曾经使用过这个令人敬畏的反应组件处理服务器端数据?
如果您不需要手动更新数据,那么给出here的解决方案非常好。
我不仅需要在更改page / pageSize /排序/过滤时刷新数据,还需要在一些间隔时间之后刷新数据,以查看数据是否已更改。
此外,我有一个表的扩展,允许用户对所有列进行全文搜索,因此我需要在用户更改自定义搜索框的内容时更新数据。
我遇到了和你一样的问题,我开始用ReactJs寻找异步测试,我发现这篇文章非常有用。关键部分是在酶组件上使用“更新”方法,如下所示:
const items = ['die Straße', 'die Adresse', 'die Nationalität'];
jest.useFakeTimers();
describe('<DelayedList />', () => {
test('it renders the items with delay', () => {
const component = shallow(
<DelayedList items={items} />
);
jest.runAllTimers();
component.update(); // <--- force re-render of the component
expect(component.state().currentIndex).toEqual(items.length);
expect(component).toMatchSnapshot();
});
有关更多信息,请参阅this medium article。