Skip to content

Commit 4bb7ab7

Browse files
committed
Add a working JEST example app.
1 parent 95eb20e commit 4bb7ab7

File tree

6 files changed

+33
-41
lines changed

6 files changed

+33
-41
lines changed

examples/with-jest/.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["next/babel"]
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
exports[`With Snapshot Testing App shows "Hello world!" 1`] = `
2+
<div>
3+
<p>
4+
Hello World!
5+
</p>
6+
</div>
7+
`;
+18-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
/* global it, expect */
1+
/* global it, expect, describe */
2+
23
import React from 'react'
34
import { shallow } from 'enzyme'
5+
import renderer from 'react-test-renderer'
46
import App from '../pages/index.js'
57

6-
it('App shows "Hello world!"', () => {
7-
const app = shallow(
8-
<App />
9-
)
8+
describe('With Enzyme', () => {
9+
it('App shows "Hello world!"', () => {
10+
const app = shallow(
11+
<App />
12+
)
13+
14+
expect(app.find('p').text()).toEqual('Hello World!')
15+
})
16+
})
1017

11-
expect(app.find('p').text()).toEqual('Hello world!')
18+
describe('With Snapshot Testing', () => {
19+
it('App shows "Hello world!"', () => {
20+
const component = renderer.create(<App />)
21+
const tree = component.toJSON()
22+
expect(tree).toMatchSnapshot()
23+
})
1224
})

examples/with-jest/package.json

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "my-app",
33
"dependencies": {
4-
"next": "^1.0.0"
4+
"next": "^2.0.0-beta",
5+
"react-test-renderer": "^15.4.1"
56
},
67
"scripts": {
78
"test": "jest",
@@ -10,17 +11,11 @@
1011
"start": "next start"
1112
},
1213
"devDependencies": {
13-
"babel-jest": "^16.0.0",
14+
"babel-jest": "^18.0.0",
1415
"enzyme": "^2.5.1",
15-
"jest": "^16.0.2",
16+
"jest-cli": "^18.0.0",
1617
"react": "^15.3.2",
1718
"react-addons-test-utils": "^15.3.2",
1819
"react-dom": "^15.3.2"
19-
},
20-
"babel": {
21-
"presets": [
22-
"es2015",
23-
"react"
24-
]
2520
}
2621
}

examples/with-jest/pages/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default () => (
22
<div>
3-
<p>Hello world!</p>
3+
<p>Hello World!</p>
44
</div>
55
)

examples/with-jest/readme.md

-25
This file was deleted.

0 commit comments

Comments
 (0)