Skip to content

Instantly share code, notes, and snippets.

@RichardBray
Created April 3, 2020 17:35
Show Gist options
  • Save RichardBray/ffd2c4bc3ee6021976fcd467f696b681 to your computer and use it in GitHub Desktop.
Save RichardBray/ffd2c4bc3ee6021976fcd467f696b681 to your computer and use it in GitHub Desktop.
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
// ...
describe('App', () => {
// ...
describe('Question', () => {
// - setup redux store
const mockReduxStore = configureStore();
const initialReduxState = { chosenAnswers: [], setChosenAnswers: () => {} };
const reduxStore = mockReduxStore(initialReduxState);
const getButton = question => question.find('Button');
const wrapperProps = index => ({ index, result: data.results[0] });
const wrapper = props => mount(<Provider store={reduxStore}><Question {...props} /></Provider>);
test('Should have only one Next button for the first question', () => {
// - when
const firstQuestion = wrapper(wrapperProps(0));
// - then
expect(getButton(firstQuestion).text()).toEqual('next');
expect(getButton(firstQuestion).length).toEqual(1);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment