Skip to content

Commit

Permalink
Merge pull request #8 from just4fun/unit-testing
Browse files Browse the repository at this point in the history
Unit testing infrastructure
  • Loading branch information
just4fun authored Mar 11, 2017
2 parents a5b5ed6 + 1250eb6 commit 3546b40
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"react-native"
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ npm run eslint
- ~~Submit to App Store~~ ([link](https://itunes.apple.com/cn/app/qing-shui-he-pan-stuhome/id1190564355))
- Replace [redux-thunk](https://github.com/gaearon/redux-thunk) with [redux-saga](https://github.com/redux-saga/redux-saga)
- Fixture data (aka `mock data`)
- Unit Testing
- ~~Unit Testing Infrastructure~~ ([#8](https://github.com/just4fun/uestc-bbs-react-native/pull/8))
- Push notification

## Known issues
Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"author": "just4fun <houritsunohikari@gmail.com>",
"scripts": {
"start": "node_modules/react-native/packager/packager.sh",
"eslint": "eslint ./src"
"eslint": "eslint ./src",
"test": "mocha --require react-native-mock/mock.js tests/mocha-setup.js tests/**/*.js"
},
"homepage": "https://github.com/just4fun/uestc-bbs-react-native#readme",
"repository": {
Expand Down Expand Up @@ -35,9 +36,16 @@
"redux-thunk": "2.0.1"
},
"devDependencies": {
"babel": "6.5.2",
"babel-core": "6.22.1",
"babel-eslint": "6.0.0-beta.6",
"babel-preset-react-native": "1.9.1",
"chai": "3.5.0",
"enzyme": "2.7.0",
"eslint": "2.4.0",
"eslint-plugin-react": "4.2.3"
"eslint-plugin-react": "4.2.3",
"mocha": "3.2.0",
"react-native-mock": "0.2.9"
},
"license": "MIT"
}
26 changes: 26 additions & 0 deletions tests/components/Content.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import {
View,
Text,
StyleSheet
} from 'react-native';
import Content from '../../src/components/Content';
import { shallow } from 'enzyme';
import { expect } from 'chai';

describe('<Content />', () => {
it('should render child components as many as `content` length', () => {
let content = [
{
infor: '书念得少,不会说什么有文化的祝福。',
type: 0
},
{
infor: '在这里先祝大家鸡年大吉吧。',
type: 0
}
];
let wrapper = shallow(<Content content={content} />);
expect(wrapper.find(Text)).to.have.length(2);
});
});
8 changes: 8 additions & 0 deletions tests/mocha-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// certain features such as ES6 modules are not yet supported in Node,
// when we add a module which uses ES6 import statements, we should use
// babel to compile them.
//
// http://stackoverflow.com/a/35045012/2798001
require('babel-register')({
ignore: /node_modules\/(?!react-native-image-progress|react-native-progress)/
});

0 comments on commit 3546b40

Please sign in to comment.