Created
June 6, 2020 02:17
-
-
Save msrose/116231dc98da488f033526fcc5b14618 to your computer and use it in GitHub Desktop.
Mock function as prop
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
module.exports = { | |
presets: ['@babel/preset-react', '@babel/preset-env'] | |
} |
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
import React from 'react' | |
import Enzyme, { mount } from 'enzyme' | |
import Adapter from 'enzyme-adapter-react-16' | |
Enzyme.configure({ adapter: new Adapter() }) | |
const Foo = ({ onClick }) => { | |
const handleClick = () => { | |
onClick() | |
} | |
return <button onClick={handleClick} /> | |
} | |
test('Foo calls onClick when button is clicked', () => { | |
const clickMock = jest.fn() | |
const wrapper = mount(<Foo onClick={clickMock} />) | |
wrapper.find('button').simulate('click') | |
expect(clickMock).toHaveBeenCalled() | |
}) |
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
{ | |
"dependencies": { | |
"@babel/preset-env": "^7.10.2", | |
"@babel/preset-react": "^7.10.1", | |
"babel-jest": "^26.0.1", | |
"enzyme": "^3.11.0", | |
"enzyme-adapter-react-16": "^1.15.2", | |
"jest": "^26.0.1", | |
"react": "^16.13.1", | |
"react-dom": "^16.13.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment