1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Adds jest configuration npm run test shows failed results (#60)

This commit is contained in:
Pavithra Kodmad 2016-10-26 15:47:02 +05:30 committed by Naoyuki Kanezawa
parent eb74ff4bf9
commit 95719c956e
4 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,12 @@
import React from 'react';
import {shallow} from 'enzyme';
import App from '../pages/index.js';
it('App shows "Hello world!"', () => {
const app = shallow(
<App/>
);
expect(app.find('p').text()).toEqual('Hello world!');
});

View file

@ -0,0 +1,17 @@
{
"name": "my-app",
"dependencies": {
"next": "^1.0.0"
},
"scripts": {
"test": "jest",
"dev": "next",
"build": "next build",
"start": "next start"
},
"devDependencies": {
"babel-jest": "^16.0.0",
"enzyme": "^2.5.1",
"jest": "^16.0.2"
}
}

View file

@ -0,0 +1,6 @@
import React from 'react'
export default () => (
<div>
<p>Hello world!</p>
</div>
)

View file

@ -0,0 +1,25 @@
## Add testing to your `next` app using `jest`
[`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`
npm install --save-dev jest babel-jest enzyme
* `jest` - The testing framework
* `babel-jest` - Babel preprocessor for test files
* `enzyme` - Mock render the elements
Add test script to the [recommended `package.json`](https://github.com/zeit/next.js#production-deployment)
__package.json__
```javascript
...
"scripts": {
"test": "jest",
...
}
...
```
`npm run test`