Created
February 2, 2018 03:06
-
-
Save mikerourke/52698c81918ef88cb624008342e0cb48 to your computer and use it in GitHub Desktop.
Refactoring Tests: Describe Block Structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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