Created
October 10, 2016 12:58
-
-
Save coder36/002a7605741abe9ccaa8b0aa9735f7c9 to your computer and use it in GitHub Desktop.
Jest and mocking
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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { mount } from 'enzyme' | |
import ReactTestUtils from 'react-addons-test-utils' | |
import * as api from './api'; | |
it('renders without crashing', () => { | |
api.sayHello = jest.fn() | |
api.sayHello.mockImplementation( (x) => "boom" ) | |
let App = require('./App').default | |
const dom = mount(<App/>) | |
dom.ref("name").node.value="mark" | |
dom.find("button").simulate( 'click' ) | |
expect(api.sayHello).toBeCalledWith("mark") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment