Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/with-jest/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["next/babel"]
}
26 changes: 26 additions & 0 deletions examples/with-jest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Example app using Jest to run tests

This example features:

* A properly configured Next.js app for Jest
* An example test written with Jest Snapshot Testing
* An example test written with Enzyme

## How to run it

```sh
npm install
npm run dev
```

## Jest related info

After you've added `jest-cli` and `jest-babel` into your app, make sure to add the following `.babelrc` file.

```json
{
"presets": ["next/babel"]
}
```

It'll ask Jest to use the babel configurations used by Next.js.
7 changes: 7 additions & 0 deletions examples/with-jest/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exports[`With Snapshot Testing App shows "Hello world!" 1`] = `
<div>
<p>
Hello World!
</p>
</div>
`;
24 changes: 18 additions & 6 deletions examples/with-jest/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
/* global it, expect */
/* global it, expect, describe */

import React from 'react'
import { shallow } from 'enzyme'
import renderer from 'react-test-renderer'
import App from '../pages/index.js'

it('App shows "Hello world!"', () => {
const app = shallow(
<App />
)
describe('With Enzyme', () => {
it('App shows "Hello world!"', () => {
const app = shallow(
<App />
)

expect(app.find('p').text()).toEqual('Hello World!')
})
})

expect(app.find('p').text()).toEqual('Hello world!')
describe('With Snapshot Testing', () => {
it('App shows "Hello world!"', () => {
const component = renderer.create(<App />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
})
15 changes: 5 additions & 10 deletions examples/with-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "my-app",
"dependencies": {
"next": "^1.0.0"
"next": "^2.0.0-beta"
},
"scripts": {
"test": "jest",
Expand All @@ -10,17 +10,12 @@
"start": "next start"
},
"devDependencies": {
"babel-jest": "^16.0.0",
"babel-jest": "^18.0.0",
"enzyme": "^2.5.1",
"jest": "^16.0.2",
"jest-cli": "^18.0.0",
"react": "^15.3.2",
"react-addons-test-utils": "^15.3.2",
"react-dom": "^15.3.2"
},
"babel": {
"presets": [
"es2015",
"react"
]
"react-dom": "^15.3.2",
"react-test-renderer": "^15.4.1"
}
}
2 changes: 1 addition & 1 deletion examples/with-jest/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default () => (
<div>
<p>Hello world!</p>
<p>Hello World!</p>
</div>
)
25 changes: 0 additions & 25 deletions examples/with-jest/readme.md

This file was deleted.