Skip to content

Instantly share code, notes, and snippets.

@xiongemi
Created April 7, 2022 04:49
Show Gist options
  • Save xiongemi/22b26063e57981ff08f481e80bba2005 to your computer and use it in GitHub Desktop.
Save xiongemi/22b26063e57981ff08f481e80bba2005 to your computer and use it in GitHub Desktop.
mock redux store unit test for react native
import {
initialRootState,
RootState,
} from '@studio-ghibli-search-engine/store';
import { render } from '@testing-library/react-native';
import React from 'react';
import { Provider } from 'react-redux';
import configureStore, { MockStoreEnhanced } from 'redux-mock-store';
import Film from './film';
describe('Film', () => {
const mockStore = configureStore<RootState>([]);
let store: MockStoreEnhanced<RootState>;
beforeEach(() => {
store = mockStore(initialRootState);
store.dispatch = jest.fn();
});
it('should render successfully', () => {
const { container } = render(
<Provider store={store}>
<Film />
</Provider>
);
expect(container).toBeTruthy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment