Skip to content

Instantly share code, notes, and snippets.

@mikerourke
Created February 2, 2018 03:06
Show Gist options
  • Save mikerourke/52698c81918ef88cb624008342e0cb48 to your computer and use it in GitHub Desktop.
Save mikerourke/52698c81918ef88cb624008342e0cb48 to your computer and use it in GitHub Desktop.
Refactoring Tests: Describe Block Structure
describe('Component A', () => {
describe('Snapshot validation', () => {
it('matches its snapshot with valid props', () => {
const { wrapper } = setup();
expect(wrapper).toMatchSnapshot();
});
});
describe('Event validation', () => {
it('fires props.onClick when button is clicked', () => {
const { wrapper, props } = setup();
wrapper.find('button').simulate('click');
expect(props.onClick).toHaveBeenCalled();
});
});
// Note: This is only for connected components.
describe('Redux validation', () => {
const store = {
getState: () => state,
dispatch: jest.fn(),
subscribe: () => {},
};
it('renders when connected to Redux state', () => {
const wrapper = shallow(<ComponentA store={store} />);
expect(wrapper).toHaveLength(1);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment