Skip to content

Commit

Permalink
Use enzyme to json instead of react-test-renderer, also fix tests and…
Browse files Browse the repository at this point in the history
… snapshots
  • Loading branch information
drublic committed Apr 10, 2018
1 parent e583c16 commit 3030d4f
Show file tree
Hide file tree
Showing 51 changed files with 1,262 additions and 2,168 deletions.
6 changes: 6 additions & 0 deletions __tests__/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { createSerializer } from 'enzyme-to-json'

Enzyme.configure({ adapter: new Adapter() })
expect.addSnapshotSerializer(createSerializer({ mode: 'deep' }))
2 changes: 0 additions & 2 deletions examples/form/data.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { Fragment } from 'react'

import Icon from '@material-ui/icons/Visibility'
import Divider from 'material-ui/Divider/Divider'
import Typography from 'material-ui/Typography/Typography'

import { TYPES } from 'backoffice/src/Form/constants'
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ module.exports = {
transform: {
'^.+\\.jsx?$': 'babel-jest',
},
setupTestFrameworkScriptFile: './__tests__/config.js',
snapshotSerializers: [
'enzyme-to-json/serializer',
],
unmockedModulePathPatterns: [
'node_modules/react/',
'node_modules/enzyme/',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@
"concurrently": "^3.5.1",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"enzyme-to-json": "^3.3.3",
"eslint": "^4.15.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.5.1",
"express": "^4.16.2",
"react-mock-router": "^1.0.11",
"react-test-renderer": "^16.2.0",
"tslint": "^5.9.1",
"tslint-react": "^3.5.1",
"typescript": "^2.7.2",
Expand Down
7 changes: 3 additions & 4 deletions src/AddButton/AddButton.test.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from 'react'
import renderer from 'react-test-renderer'
import { mount } from 'enzyme'

import AddButton from './'

it('renders correctly', () => {
const tree = renderer
.create(<AddButton handleClick={() => {}} />)
.toJSON()
const tree = mount(<AddButton onClick={() => {}} />)

expect(tree).toMatchSnapshot()
})
11 changes: 6 additions & 5 deletions src/AddButton/__snapshots__/AddButton.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`renders correctly 1`] = `
className="MuiButtonBase-root-17 MuiButton-root-2 MuiButton-raised-7 MuiButton-fab-12 MuiButton-raisedSecondary-10 AddButton-button-1"
disabled={false}
onBlur={[Function]}
onClick={undefined}
onClick={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
Expand All @@ -25,13 +25,14 @@ exports[`renders correctly 1`] = `
<svg
aria-hidden="true"
className="MuiSvgIcon-root-20"
color={undefined}
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"
/>
<g>
<path
d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"
/>
</g>
</svg>
</span>
<span
Expand Down
15 changes: 7 additions & 8 deletions src/AppContainer/AppContainer.test.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import React from 'react'
import renderer from 'react-test-renderer'
import { mount } from 'enzyme'

import AppContainer from './'

describe('Component Info', () => {
it('renders correctly', () => {
const tree = renderer
.create((
<AppContainer>
Foo
</AppContainer>
))
.toJSON()
const tree = mount((
<AppContainer>
Foo
</AppContainer>
))

expect(tree).toMatchSnapshot()
})
})
11 changes: 3 additions & 8 deletions src/BackButton/BackButton.test.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import React from 'react'
import MockRouter from 'react-mock-router'
import renderer from 'react-test-renderer'
import Enzyme, { mount } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { mount } from 'enzyme'

import BackButton from './'

Enzyme.configure({ adapter: new Adapter() })

describe('Back Button', () => {
it('renders correctly', () => {
const tree = renderer
.create((<MockRouter><BackButton url="/" /></MockRouter>))
.toJSON()
const tree = mount((<MockRouter><BackButton url="/" /></MockRouter>))

expect(tree).toMatchSnapshot()
})

Expand Down
9 changes: 5 additions & 4 deletions src/BackButton/__snapshots__/BackButton.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ exports[`Back Button renders correctly 1`] = `
<svg
aria-hidden="true"
className="MuiSvgIcon-root-20 BackButtonBranch-leftIcon-1"
color={undefined}
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M15.41 16.09l-4.58-4.59 4.58-4.59L14 5.5l-6 6 6 6z"
/>
<g>
<path
d="M15.41 16.09l-4.58-4.59 4.58-4.59L14 5.5l-6 6 6 6z"
/>
</g>
</svg>
Back
</span>
Expand Down
90 changes: 43 additions & 47 deletions src/Base/Base.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'
import MockRouter from 'react-mock-router'
import renderer from 'react-test-renderer'
import Enzyme from 'enzyme'
import Enzyme, { mount } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

import Base from './'
Expand All @@ -12,59 +11,56 @@ Enzyme.configure({ adapter: new Adapter() })

describe('Base', () => {
it('renders correctly', () => {
const tree = renderer
.create((
<MockRouter>
<Base
title="Foo"
menuData={menuData}
hasCookieInfo
menuOpen
>
<div>Foo</div>
</Base>
</MockRouter>
))
.toJSON()
const tree = mount((
<MockRouter>
<Base
title="Foo"
menuData={menuData}
hasCookieInfo
menuOpen
>
<div>Foo</div>
</Base>
</MockRouter>
))

expect(tree).toMatchSnapshot()
})

it('renders correctly without header', () => {
const tree = renderer
.create((
<MockRouter>
<Base
title="Foo"
menuData={menuData}
hasCookieInfo
hasHeader={false}
menuOpen
>
<div>Foo</div>
</Base>
</MockRouter>
))
.toJSON()
const tree = mount((
<MockRouter>
<Base
title="Foo"
menuData={menuData}
hasCookieInfo
hasHeader={false}
menuOpen
>
<div>Foo</div>
</Base>
</MockRouter>
))

expect(tree).toMatchSnapshot()
})

it('renders with drawer open', () => {
const tree = renderer
.create((
<MockRouter>
<Base
open
title="Foo"
menuData={menuData}
hasCookieInfo
hasHeader={false}
menuOpen
>
<div>Foo</div>
</Base>
</MockRouter>
))
.toJSON()
const tree = mount((
<MockRouter>
<Base
open
title="Foo"
menuData={menuData}
hasCookieInfo
hasHeader={false}
menuOpen
>
<div>Foo</div>
</Base>
</MockRouter>
))

expect(tree).toMatchSnapshot()
})
})
37 changes: 19 additions & 18 deletions src/Base/__snapshots__/Base.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ exports[`Base renders correctly 1`] = `
<svg
aria-hidden="true"
className="MuiSvgIcon-root-59"
color={undefined}
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"
/>
<g>
<path
d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"
/>
</g>
</svg>
</span>
<span
Expand All @@ -68,9 +69,7 @@ exports[`Base renders correctly 1`] = `
direction="right"
style={Object {}}
>
<div
className={undefined}
>
<div>
<div
className="Drawer-drawerHeader-97"
>
Expand All @@ -97,13 +96,14 @@ exports[`Base renders correctly 1`] = `
<svg
aria-hidden="true"
className="MuiSvgIcon-root-59"
color={undefined}
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"
/>
<g>
<path
d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"
/>
</g>
</svg>
</span>
<span
Expand Down Expand Up @@ -200,13 +200,14 @@ exports[`Base renders correctly 1`] = `
<svg
aria-hidden="true"
className="MuiSvgIcon-root-59 MuiListItemIcon-root-135"
color={undefined}
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M20 8h-2.81c-.45-.78-1.07-1.45-1.82-1.96L17 4.41 15.59 3l-2.17 2.17C12.96 5.06 12.49 5 12 5c-.49 0-.96.06-1.41.17L8.41 3 7 4.41l1.62 1.63C7.88 6.55 7.26 7.22 6.81 8H4v2h2.09c-.05.33-.09.66-.09 1v1H4v2h2v1c0 .34.04.67.09 1H4v2h2.81c1.04 1.79 2.97 3 5.19 3s4.15-1.21 5.19-3H20v-2h-2.09c.05-.33.09-.66.09-1v-1h2v-2h-2v-1c0-.34-.04-.67-.09-1H20V8zm-6 8h-4v-2h4v2zm0-4h-4v-2h4v2z"
/>
<g>
<path
d="M20 8h-2.81c-.45-.78-1.07-1.45-1.82-1.96L17 4.41 15.59 3l-2.17 2.17C12.96 5.06 12.49 5 12 5c-.49 0-.96.06-1.41.17L8.41 3 7 4.41l1.62 1.63C7.88 6.55 7.26 7.22 6.81 8H4v2h2.09c-.05.33-.09.66-.09 1v1H4v2h2v1c0 .34.04.67.09 1H4v2h2.81c1.04 1.79 2.97 3 5.19 3s4.15-1.21 5.19-3H20v-2h-2.09c.05-.33.09-.66.09-1v-1h2v-2h-2v-1c0-.34-.04-.67-.09-1H20V8zm-6 8h-4v-2h4v2zm0-4h-4v-2h4v2z"
/>
</g>
</svg>
<div
className="MuiListItemText-root-129"
Expand Down Expand Up @@ -240,6 +241,7 @@ exports[`Base renders correctly 1`] = `
}
}
isOpen={true}
key=".0"
location=""
match={
Object {
Expand All @@ -250,7 +252,6 @@ exports[`Base renders correctly 1`] = `
}
menuOpen={true}
onAccept={[Function]}
staticContext={undefined}
>
Foo
</div>
Expand Down Expand Up @@ -278,6 +279,7 @@ exports[`Base renders correctly without header 1`] = `
}
}
isOpen={true}
key=".0"
location=""
match={
Object {
Expand All @@ -288,7 +290,6 @@ exports[`Base renders correctly without header 1`] = `
}
menuOpen={true}
onAccept={[Function]}
staticContext={undefined}
>
Foo
</div>
Expand Down Expand Up @@ -316,6 +317,7 @@ exports[`Base renders with drawer open 1`] = `
}
}
isOpen={true}
key=".0"
location=""
match={
Object {
Expand All @@ -326,7 +328,6 @@ exports[`Base renders with drawer open 1`] = `
}
menuOpen={true}
onAccept={[Function]}
staticContext={undefined}
>
Foo
</div>
Expand Down
Loading

0 comments on commit 3030d4f

Please sign in to comment.