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 renderer from 'react-test-renderer' | |
import Input from '../Input' | |
it('should render correctly', () => { | |
const component = renderer.create(<Input />) | |
expect(component.toJSON()).toMatchSnapshot() | |
// getInstance is returning the `this` object you have in your component | |
// meaning anything accessible on `this` inside your component | |
// can be accessed on getInstance, including props! |
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
{ | |
"jest": { | |
"setupFiles": [ | |
"<rootDir>/test-setup.js" | |
] | |
} | |
} |
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
{ | |
"jest": { | |
"setupFiles": [ | |
"<rootDir>/test-setup.js" | |
] | |
} | |
} |
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 renderer from 'react-test-renderer' | |
import App from '../App' | |
// Generated snapshot is exactly like the previous example | |
// while it's possible to override the default mock | |
// by using the same jest.mock command as before | |
// if this test need a different behavior than the | |
// glboal mock. | |
it('should render correctly', () => { |
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 renderer from 'react-test-renderer' | |
import App from '../App' | |
jest.mock('react-router-dom', () => ({ | |
Link: 'Link', | |
Route: ({ children, ...props }) => | |
typeof children === 'function' | |
? children({ match: path === '/somewhere' }) | |
: createElement('Route', props) | |
})) |
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 renderer from 'react-test-renderer' | |
import Select from '../Select' | |
jest.mock('react-select', () => { | |
const { createElement } = require('react') | |
// Note that since 'react-select' is mocked we have to use | |
// require.requireActual, even inside the factory function that mocks it! | |
// Just watch the movie Inception and skip to the Dream within a Dream and you'll get it | |
const ReactSelect = require.requireActual('react-select') |
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 renderer from 'react-test-renderer' | |
import Header from '../Header' | |
import store from '../store' | |
jest.mock('react-redux-loading-bar', () => { | |
const ReactReduxLoadingBar = require.requireActual('react-redux-loading-bar') | |
return { | |
// Spread out the original module | |
...ReactReduxLoadingBar, |