Skip to content

Instantly share code, notes, and snippets.

@aofleejay
Created July 3, 2017 13:41
Show Gist options
  • Save aofleejay/631a67e2d0db163b2dce40810887eb5f to your computer and use it in GitHub Desktop.
Save aofleejay/631a67e2d0db163b2dce40810887eb5f to your computer and use it in GitHub Desktop.
React Snapshot Testing
import React from 'react'
import renderer from 'react-test-renderer'
import shallowRenderer from 'react-test-renderer/shallow'
import App from './App'
describe('Test app component', () => {
it('shallow snapshot', () => {
const renderer = new shallowRenderer
const snapshot = renderer.render(<App />)
expect(snapshot).toMatchSnapshot()
})
it('full snapshot', () => {
const html = renderer.create(<App />).toJSON()
expect(html).toMatchSnapshot()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment