Skip to content

Instantly share code, notes, and snippets.

@RichardBray
Last active April 3, 2020 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardBray/014c1cf443b0f241581127e2e3379463 to your computer and use it in GitHub Desktop.
Save RichardBray/014c1cf443b0f241581127e2e3379463 to your computer and use it in GitHub Desktop.
import * as Store from "./AppContext";
// ...
describe('App', () => {
// ...
describe('Question', () => {
// - context spy
const contextValues = { chosenAnswers: [], setChosenAnswers: () => {} };
jest.spyOn(Store, 'useAppContext').mockImplementation(() => contextValues);
const getButton = question => question.find('Button');
const wrapperProps = index => ({ index, result: data.results[0] });
const wrapper = props => mount(<Question {...props} />);
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