Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit testing infrastructure #8

Merged
merged 4 commits into from
Mar 11, 2017
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
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 <[email protected]>",
"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)/
});