Skip to content

Commit 95719c9

Browse files
Pavithra Kodmadnkzawa
Pavithra Kodmad
authored andcommitted
Adds jest configuration npm run test shows failed results (vercel#60)
1 parent eb74ff4 commit 95719c9

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import React from 'react';
3+
import {shallow} from 'enzyme';
4+
import App from '../pages/index.js';
5+
6+
it('App shows "Hello world!"', () => {
7+
const app = shallow(
8+
<App/>
9+
);
10+
11+
expect(app.find('p').text()).toEqual('Hello world!');
12+
});

examples/with-jest/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "my-app",
3+
"dependencies": {
4+
"next": "^1.0.0"
5+
},
6+
"scripts": {
7+
"test": "jest",
8+
"dev": "next",
9+
"build": "next build",
10+
"start": "next start"
11+
},
12+
"devDependencies": {
13+
"babel-jest": "^16.0.0",
14+
"enzyme": "^2.5.1",
15+
"jest": "^16.0.2"
16+
}
17+
}

examples/with-jest/pages/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react'
2+
export default () => (
3+
<div>
4+
<p>Hello world!</p>
5+
</div>
6+
)

examples/with-jest/readme.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Add testing to your `next` app using `jest`
2+
3+
[`jest`](https://facebook.github.io/jest/) is a testing framework for `react`. In this example we show how to use `jest` to do DOM-testing for react applications in `next`
4+
5+
npm install --save-dev jest babel-jest enzyme
6+
7+
* `jest` - The testing framework
8+
* `babel-jest` - Babel preprocessor for test files
9+
* `enzyme` - Mock render the elements
10+
11+
Add test script to the [recommended `package.json`](https://github.com/zeit/next.js#production-deployment)
12+
13+
__package.json__
14+
15+
```javascript
16+
...
17+
"scripts": {
18+
"test": "jest",
19+
...
20+
}
21+
...
22+
23+
```
24+
25+
`npm run test`

0 commit comments

Comments
 (0)