You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After adding redux persist, the jest test fails, because the react-test renderer do not renders the app (returns null). App in Simulator is working. Even when I do not use a component with connect (removing Component from App.js) error did not appear, but the test-renderer returns still a null.
import React from 'react';
import 'react-native';
import App from '@';
import renderer from 'react-test-renderer';
it('App renders without crashing', () => {
const rendered = renderer.create(<App />).toJSON();
expect(rendered).toBeTruthy();
});
The App Component - App.js
/* flow */
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createStore, applyMiddleware } from 'redux';
import { persistStore, persistReducer } from 'redux-persist';
import { PersistGate } from 'redux-persist/integration/react';
import storage from 'redux-persist/lib/storage';
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2';
import { Provider } from 'react-redux';
import axios from 'axios';
import axiosMiddleware from 'redux-axios-middleware';
import I18n from '@/i18n';
import reducer from '@/reducers/repos';
import RepoList from './repoList';
const persistConfig = {
key: 'root',
storage,
stateReconciler: autoMergeLevel2
};
const client = axios.create({
baseURL: 'https://api.github.com',
responseType: 'json',
});
const persistedReducer = persistReducer(persistConfig, reducer);
const store = createStore(persistedReducer, {}, applyMiddleware(axiosMiddleware(client)));
const persistor = persistStore(store);
type Props = {}
const styles: StyleSheet.Styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
marginTop: 50,
},
});
export default class App extends React.Component<Props> {
render() {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<View style={styles.container}>
<Text>{I18n.t('greeting')}</Text>
<Text>{I18n.t('start1')}</Text>
<Text>{I18n.t('start2')}</Text>
<Text>{I18n.t('start3')}</Text>
<RepoList />
</View>
</PersistGate>
</Provider>
);
}
}
The Error Output
✕ App renders without crashing (3146ms)
● App renders without crashing
expect(received).toBeTruthy()
Expected value to be truthy, instead received
null
7 | it('App renders without crashing', () => {
8 | const rendered = renderer.create(<App />).toJSON();
> 9 | expect(rendered).toBeTruthy();
10 | });
11 |
at Object.<anonymous> (tests/App.test.js:9:20)
console.error node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5530
The above error occurred in the <Connect(RepoList)> component:
in Connect(RepoList) (created by App)
in View (created by View)
in View (created by App)
in PersistGate (created by App)
in Provider (created by App)
in App
Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://fb.me/react-error-boundaries to learn more about error boundaries.
The text was updated successfully, but these errors were encountered:
it returns null because null is the value you specified as the property loading of your PersistGate component. renderer.create() sends you the element at the mount time, and not through eventual updates. Here, at mount time, PersistGate will show you the loading. Maybe use mount from enzyme, or mock PersistGate, something like this:
This seems to be a gotcha with Jest and async components that was sorted out. I'm happy to merge a PR or docs update if appropriate for the project, but closing this for now.
After adding redux persist, the jest test fails, because the react-test renderer do not renders the app (returns null). App in Simulator is working. Even when I do not use a component with connect (removing Component from App.js) error did not appear, but the test-renderer returns still a null.
react-native info
package.json
The Test - App.test.js
The App Component - App.js
The Error Output
The text was updated successfully, but these errors were encountered: