Skip to content

Commit

Permalink
Update some tests to use shallow, better setup for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drublic committed Jun 13, 2019
1 parent f1dd695 commit 6cdc7ab
Show file tree
Hide file tree
Showing 66 changed files with 12,694 additions and 8,023 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
language: node_js
node_js:
- "8"
- "10"
- "12"
cache:
yarn: true
directories:
- "node_modules"
before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.3.2
- export PATH="$HOME/.yarn/bin:$PATH"
- export TZ=Europe/Berlin
before_script:
- yarn add react react-dom prop-types
Expand Down
6 changes: 0 additions & 6 deletions __tests__/config.js

This file was deleted.

9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.13.0",
"express": "^4.17.1",
"jest-enzyme": "^7.0.2",
"react-mock-router": "^1.0.15",
"react-scripts": "^3.0.1",
"tslint": "^5.17.0",
Expand All @@ -78,6 +79,14 @@
"dashboard",
"material-ui"
],
"jest": {
"watchPathIgnorePatterns": [
"node_modules",
"build",
"coverage",
"dist"
]
},
"browserslist": {
"production": [
">0.2%",
Expand Down
6 changes: 3 additions & 3 deletions src/AddButton/AddButton.test.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react'
import { mount } from 'enzyme'
import { shallow } from 'enzyme'

import AddButton from './'
import AddButton from '.'

it('renders correctly', () => {
const tree = mount(<AddButton onClick={() => {}} />)
const tree = shallow(<AddButton onClick={() => {}} />)

expect(tree).toMatchSnapshot()
})
48 changes: 7 additions & 41 deletions src/AddButton/__snapshots__/AddButton.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -1,46 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
<button
aria-label="add"
className="MuiButtonBase-root-12 MuiFab-root-2 MuiFab-secondary-5 AddButton-button-1"
disabled={false}
onBlur={[Function]}
<AddButton
classes={
Object {
"button": "AddButton-button-1",
}
}
onClick={[Function]}
onContextMenu={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
tabIndex="0"
type="button"
>
<span
className="MuiFab-label-3"
>
<svg
aria-hidden="true"
className="MuiSvgIcon-root-15"
focusable="false"
role="presentation"
viewBox="0 0 24 24"
>
<path
d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"
/>
<path
d="M0 0h24v24H0z"
fill="none"
/>
</svg>
</span>
<span
className="MuiTouchRipple-root-24"
/>
</button>
/>
`;
6 changes: 3 additions & 3 deletions src/AppContainer/AppContainer.test.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import { mount } from 'enzyme'
import { shallow } from 'enzyme'

import AppContainer from './'
import AppContainer from '.'

describe('Component Info', () => {
it('renders correctly', () => {
const tree = mount((
const tree = shallow((
<AppContainer>
Foo
</AppContainer>
Expand Down
2 changes: 1 addition & 1 deletion src/AppContainer/__snapshots__/AppContainer.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Component Info renders correctly 1`] = `"Foo"`;
exports[`Component Info renders correctly 1`] = `<withRoot(BaseComponent) />`;
6 changes: 3 additions & 3 deletions src/BackButton/BackButton.test.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import React from 'react'
import MockRouter from 'react-mock-router'
import { mount } from 'enzyme'
import { shallow } from 'enzyme'

import BackButton from '.'

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

expect(tree).toMatchSnapshot()
})

it('updates history on click', () => {
const push = jest.fn()
const button = mount(<MockRouter push={push}><BackButton url="/" /></MockRouter>)
const button = shallow(<MockRouter push={push}><BackButton url="/" /></MockRouter>)

button.find(BackButton).simulate('click')

Expand Down
43 changes: 3 additions & 40 deletions src/BackButton/__snapshots__/BackButton.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -1,44 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Back Button renders correctly 1`] = `
<button
className="MuiButtonBase-root-28 MuiButton-root-2 MuiButton-text-4 MuiButton-flat-7"
disabled={false}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseLeave={[Function]}
onMouseUp={[Function]}
onTouchEnd={[Function]}
onTouchMove={[Function]}
onTouchStart={[Function]}
tabIndex="0"
type="button"
>
<span
className="MuiButton-label-3"
>
<svg
aria-hidden="true"
className="MuiSvgIcon-root-31 BackButtonBranch-leftIcon-1"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M11.67 3.87L9.9 2.1 0 12l9.9 9.9 1.77-1.77L3.54 12z"
/>
<path
d="M0 0h24v24H0z"
fill="none"
/>
</svg>
Back
</span>
<span
className="MuiTouchRipple-root-38"
/>
</button>
<withRouter(_class)
url="/"
/>
`;
20 changes: 10 additions & 10 deletions src/Base/Base.test.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react'
import MockRouter from 'react-mock-router'
import Enzyme, { mount } from 'enzyme'
import Enzyme, { shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { Typography, IconButton, Button } from '@material-ui/core'

import Base from './'
import Base from '.'

import menuData from '../../__tests__/data/menu'
import menuData from '../tests/data/menu'
import Header from '../Header'
import Drawer from '../Drawer'
import CookieInfo from '../CookieInfo'
Expand All @@ -15,7 +15,7 @@ Enzyme.configure({ adapter: new Adapter() })

describe('Base', () => {
it('renders correctly', () => {
const tree = mount((
const tree = shallow((
<MockRouter>
<Base
title="Foo"
Expand All @@ -32,7 +32,7 @@ describe('Base', () => {
})

it('renders correctly without header', () => {
const tree = mount((
const tree = shallow((
<MockRouter>
<Base
title="Foo"
Expand All @@ -50,7 +50,7 @@ describe('Base', () => {
})

it('renders with drawer open', () => {
const tree = mount((
const tree = shallow((
<MockRouter>
<Base
isOpen
Expand All @@ -69,7 +69,7 @@ describe('Base', () => {
})

it('click on title', () => {
const tree = mount((
const tree = shallow((
<MockRouter>
<Base
isOpen
Expand All @@ -89,7 +89,7 @@ describe('Base', () => {
})

it('click on menu icon if open changes state', () => {
const tree = mount((
const tree = shallow((
<MockRouter>
<Base
isOpen
Expand All @@ -109,7 +109,7 @@ describe('Base', () => {
})

it('click on menu icon if closed changes state', () => {
const tree = mount((
const tree = shallow((
<MockRouter>
<Base
isOpen={false}
Expand All @@ -129,7 +129,7 @@ describe('Base', () => {
})

it('call function when cookie is accepted', () => {
const tree = mount((
const tree = shallow((
<MockRouter>
<Base
isOpen={false}
Expand Down
Loading

0 comments on commit 6cdc7ab

Please sign in to comment.