diff --git a/__tests__/config.js b/__tests__/config.js new file mode 100644 index 0000000..e320d20 --- /dev/null +++ b/__tests__/config.js @@ -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' })) diff --git a/examples/form/data.jsx b/examples/form/data.jsx index fe845c1..7c0fab2 100644 --- a/examples/form/data.jsx +++ b/examples/form/data.jsx @@ -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' diff --git a/jest.config.js b/jest.config.js index c0df590..d722c1c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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/', diff --git a/package.json b/package.json index a15b70a..f9a4fde 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "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", @@ -68,7 +69,6 @@ "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", diff --git a/src/AddButton/AddButton.test.jsx b/src/AddButton/AddButton.test.jsx index 2e06f66..f3c7f7f 100644 --- a/src/AddButton/AddButton.test.jsx +++ b/src/AddButton/AddButton.test.jsx @@ -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( {}} />) - .toJSON() + const tree = mount( {}} />) + expect(tree).toMatchSnapshot() }) diff --git a/src/AddButton/__snapshots__/AddButton.test.jsx.snap b/src/AddButton/__snapshots__/AddButton.test.jsx.snap index a6f9549..b70d924 100644 --- a/src/AddButton/__snapshots__/AddButton.test.jsx.snap +++ b/src/AddButton/__snapshots__/AddButton.test.jsx.snap @@ -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]} @@ -25,13 +25,14 @@ exports[`renders correctly 1`] = ` { it('renders correctly', () => { - const tree = renderer - .create(( - - Foo - - )) - .toJSON() + const tree = mount(( + + Foo + + )) + expect(tree).toMatchSnapshot() }) }) diff --git a/src/BackButton/BackButton.test.jsx b/src/BackButton/BackButton.test.jsx index 72df2ac..c4ae9ec 100644 --- a/src/BackButton/BackButton.test.jsx +++ b/src/BackButton/BackButton.test.jsx @@ -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(()) - .toJSON() + const tree = mount(()) + expect(tree).toMatchSnapshot() }) diff --git a/src/BackButton/__snapshots__/BackButton.test.jsx.snap b/src/BackButton/__snapshots__/BackButton.test.jsx.snap index e52d999..69355e4 100644 --- a/src/BackButton/__snapshots__/BackButton.test.jsx.snap +++ b/src/BackButton/__snapshots__/BackButton.test.jsx.snap @@ -24,13 +24,14 @@ exports[`Back Button renders correctly 1`] = ` Back diff --git a/src/Base/Base.test.jsx b/src/Base/Base.test.jsx index c8e8a9f..4c35621 100644 --- a/src/Base/Base.test.jsx +++ b/src/Base/Base.test.jsx @@ -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 './' @@ -12,59 +11,56 @@ Enzyme.configure({ adapter: new Adapter() }) describe('Base', () => { it('renders correctly', () => { - const tree = renderer - .create(( - - -
Foo
- -
- )) - .toJSON() + const tree = mount(( + + +
Foo
+ +
+ )) + expect(tree).toMatchSnapshot() }) it('renders correctly without header', () => { - const tree = renderer - .create(( - - -
Foo
- -
- )) - .toJSON() + const tree = mount(( + + +
Foo
+ +
+ )) + expect(tree).toMatchSnapshot() }) it('renders with drawer open', () => { - const tree = renderer - .create(( - - -
Foo
- -
- )) - .toJSON() + const tree = mount(( + + +
Foo
+ +
+ )) + expect(tree).toMatchSnapshot() }) }) diff --git a/src/Base/__snapshots__/Base.test.jsx.snap b/src/Base/__snapshots__/Base.test.jsx.snap index c4d4fde..c6933cc 100644 --- a/src/Base/__snapshots__/Base.test.jsx.snap +++ b/src/Base/__snapshots__/Base.test.jsx.snap @@ -35,13 +35,14 @@ exports[`Base renders correctly 1`] = ` -
+
@@ -97,13 +96,14 @@ exports[`Base renders correctly 1`] = `
@@ -316,6 +317,7 @@ exports[`Base renders with drawer open 1`] = ` } } isOpen={true} + key=".0" location="" match={ Object { @@ -326,7 +328,6 @@ exports[`Base renders with drawer open 1`] = ` } menuOpen={true} onAccept={[Function]} - staticContext={undefined} > Foo
diff --git a/src/Confirm/Confirm.test.jsx b/src/Confirm/Confirm.test.jsx index 396bdba..1980b9f 100644 --- a/src/Confirm/Confirm.test.jsx +++ b/src/Confirm/Confirm.test.jsx @@ -1,6 +1,5 @@ import React from 'react' -import renderer from 'react-test-renderer' -import Enzyme, { shallow } from 'enzyme' +import Enzyme, { shallow, mount } from 'enzyme' import Adapter from 'enzyme-adapter-react-16' import Confirm from './' @@ -9,13 +8,12 @@ Enzyme.configure({ adapter: new Adapter() }) describe('Confirm', () => { it('renders correctly', () => { - const tree = renderer - .create( { }} - />) - .toJSON() + const tree = mount( { }} + />) + expect(tree).toMatchSnapshot() }) diff --git a/src/Confirm/__snapshots__/Confirm.test.jsx.snap b/src/Confirm/__snapshots__/Confirm.test.jsx.snap index 40751b7..5841f8f 100644 --- a/src/Confirm/__snapshots__/Confirm.test.jsx.snap +++ b/src/Confirm/__snapshots__/Confirm.test.jsx.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Confirm renders correctly 1`] = `null`; +exports[`Confirm renders correctly 1`] = `""`; diff --git a/src/CookieInfo/CookieInfo.test.jsx b/src/CookieInfo/CookieInfo.test.jsx index d5b7cf2..f1a7613 100644 --- a/src/CookieInfo/CookieInfo.test.jsx +++ b/src/CookieInfo/CookieInfo.test.jsx @@ -1,5 +1,4 @@ import React from 'react' -import renderer from 'react-test-renderer' import Enzyme, { mount } from 'enzyme' import Adapter from 'enzyme-adapter-react-16' import { Button } from 'material-ui' @@ -11,9 +10,8 @@ Enzyme.configure({ adapter: new Adapter() }) describe('Component Info', () => { it('renders correctly', () => { - const tree = renderer - .create(Foo) - .toJSON() + const tree = mount(Foo) + expect(tree).toMatchSnapshot() }) diff --git a/src/Dashboard/Dashboard.test.jsx b/src/Dashboard/Dashboard.test.jsx index 8cbdac2..f2cd351 100644 --- a/src/Dashboard/Dashboard.test.jsx +++ b/src/Dashboard/Dashboard.test.jsx @@ -1,28 +1,27 @@ import React from 'react' import { BrowserRouter as Router } from 'react-router-dom' -import renderer from 'react-test-renderer' +import { mount } from 'enzyme' import Dashboard from './' it('renders correctly', () => { - const tree = renderer - .create(( - - + - - )) - .toJSON() + }], + }} + /> + + )) + expect(tree).toMatchSnapshot() }) diff --git a/src/Dashboard/DashboardCard.test.jsx b/src/Dashboard/DashboardCard.test.jsx index 0a2e455..83407be 100644 --- a/src/Dashboard/DashboardCard.test.jsx +++ b/src/Dashboard/DashboardCard.test.jsx @@ -1,28 +1,29 @@ import React from 'react' -import renderer from 'react-test-renderer' +import { mount } from 'enzyme' import DashboardCard from './DashboardCard' it('renders correctly', () => { - const tree = renderer - .create( { }} - />) - .toJSON() + const tree = mount( { }} + />) + expect(tree).toMatchSnapshot() }) it('renders disabled', () => { - const tree = renderer - .create( { }} isDisabled - />) - .toJSON() + /> + )) + + expect(tree).toMatchSnapshot() }) diff --git a/src/Dashboard/DashboardGroup.jsx b/src/Dashboard/DashboardGroup.jsx index d158fd9..80e319d 100644 --- a/src/Dashboard/DashboardGroup.jsx +++ b/src/Dashboard/DashboardGroup.jsx @@ -27,10 +27,10 @@ const DashboardGroup = ({
- + {cards ? cards.map(card => ( - + { - const tree = renderer - .create() - .toJSON() + const tree = mount( {}} + />) + expect(tree).toMatchSnapshot() }) diff --git a/src/Dashboard/__snapshots__/DashboardCard.test.jsx.snap b/src/Dashboard/__snapshots__/DashboardCard.test.jsx.snap index d106fab..a3fecf9 100644 --- a/src/Dashboard/__snapshots__/DashboardCard.test.jsx.snap +++ b/src/Dashboard/__snapshots__/DashboardCard.test.jsx.snap @@ -33,13 +33,14 @@ exports[`renders disabled 1`] = `

{ - const tree = renderer - .create( {}} - redirectTo={() => {}} - />) - .toJSON() + const tree = mount( {}} + redirectTo={() => {}} + />) + expect(tree).toMatchSnapshot() }) diff --git a/src/Drawer/__snapshots__/Drawer.test.jsx.snap b/src/Drawer/__snapshots__/Drawer.test.jsx.snap index 444f4a8..94b6a87 100644 --- a/src/Drawer/__snapshots__/Drawer.test.jsx.snap +++ b/src/Drawer/__snapshots__/Drawer.test.jsx.snap @@ -9,9 +9,7 @@ exports[`renders correctly 1`] = ` direction="right" style={Object {}} > -
+
@@ -38,13 +36,14 @@ exports[`renders correctly 1`] = `

-
-
-