Skip to content

Instantly share code, notes, and snippets.

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
expect(ReactDOM.unmountComponentAtNode(div)).toEqual(true);
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
"setupFiles": [
"./src/setupTests.js"
]
import React from 'react';
import Button from './Button';
import { shallow } from 'enzyme';
it('should render without crashing', () => {
shallow(<Button />);
});
import React, { Component } from 'react';
class Button extends React.Component {
render() {
return (
<button>OK</button>
);
}
}
import renderer from 'react-test-renderer';
it('should match the snapshot', () => {
const component = renderer.create(
<Button />
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`should match the snapshot 1`] = `
<button>
OK
</button>
it('should display the correct text', () => {
const wrapper = shallow(<Button text="Hit me"/>);
const buttonText = 'Hit me';
expect(wrapper.contains(buttonText)).toEqual(true);
});
render() {
return (
<button>{this.props.text || 'OK'}</button>
);
}