Skip to content

Instantly share code, notes, and snippets.

@coder36
Created October 10, 2016 12:58
Show Gist options
  • Save coder36/002a7605741abe9ccaa8b0aa9735f7c9 to your computer and use it in GitHub Desktop.
Save coder36/002a7605741abe9ccaa8b0aa9735f7c9 to your computer and use it in GitHub Desktop.
Jest and mocking
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