Created
July 16, 2019 11:39
-
-
Save roNn23/cc5b8a65750af3487f251174623cb672 to your computer and use it in GitHub Desktop.
React/Jest Testing #react #js #testing
This file contains hidden or 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
// simple component test | |
import React from 'react'; | |
import { shallow } from 'enzyme'; | |
import Button from './Button'; | |
function setupComponent (props) { | |
return shallow(<Button {...props} />); | |
} | |
it('should render the button', () => { | |
let component = setupComponent(); | |
expect(component.find('button')).toHaveLength(1); | |
}); | |
it('should call the callback when clicked', () => { | |
let callback = jest.fn(); | |
let component = setupComponent({ | |
onClick: callback | |
}); | |
component.simulate('click'); | |
expect(callback).toBeCalled(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment