我有以下代码:
const App = () => {
return (
<Provider store={store}>
<PersistGate persistor={persistor} loading={<Text>Loading!</Text>}>
<ConnectedRootComponent />
</PersistGate>
</Provider>
);
};
export default App;
它使用 redux-persist 来重新水化状态,在完成之前,它将显示加载属性中的内容。我有一个 Jest 测试(只是开箱即用的 react native 附带的默认测试):
it('renders without crashing', () => {
const rendered = renderer.create(<App />).toJSON();
console.log("Rendering: " + JSON.stringify(rendered));
expect(rendered).toBeTruthy();
});
但是尽管测试通过了,但我看到仍然发生的动作,persist/PERSIST
以及在测试中打印到控制台的值(呈现的输出)是:persist/REHYDRATE
{
"type": "Text",
"props": {
"accessible": true,
"allowFontScaling": true,
"ellipsizeMode": "tail"
},
"children": ["Loading!"]
}
我要做的是等到 redux-persist 完成水合,然后检查渲染值。我怎样才能做到这一点?