Skip to content

Commit

Permalink
feat: 增加jest测试
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczj committed Aug 14, 2018
1 parent 5acbef2 commit 2f523d0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ coverage/
git_stats/
yarn-offline/
docs/
test.js
jest.config.js
__mock__/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ project.config.json
.DS_Store
.vscode
.eslintcache
.babelrc
1 change: 1 addition & 0 deletions __mock__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
17 changes: 17 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
verbose: true,
moduleFileExtensions: ['js', 'jsx', 'json'],
rootDir: __dirname,
testMatch: ['<rootDir>/src/components/**/test.js'],
transform: {
'^.+\\.js?$': 'babel-jest'
},
transformIgnorePatterns: ['<rootDir>/node_modules/'],
moduleNameMapper: {
react: 'nervjs',
'react-addons-test-utils': 'nerv-test-utils',
'react-dom': 'nervjs',
'weui': '<rootDir>/__mock__/styleMock.js',
'\\.(css|less|sass|scss)$': '<rootDir>/__mock__/styleMock.js'
}
}
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
"description": "UI KIT for Taro",
"main": "index.js",
"scripts": {
"dev:weapp": "npm run build:weapp -- --watch",
"dev:h5": "npm run build:h5 -- --watch",
"dev:weapp": "rm -f .babelrc && npm run build:weapp -- --watch",
"dev:h5": "rm -f .babelrc && npm run build:h5 -- --watch",
"dev:doc": "node ./build/dev-server",
"build:weapp": "taro build --type weapp",
"build:h5": "taro build --type h5",
"build:weapp": "rm -f .babelrc && taro build --type weapp",
"build:h5": "rm -f .babelrc && taro build --type h5",
"lint": "eslint ./src --fix",
"lint:style": "stylelint \"src/**/*.scss\" --syntax scss",
"lint:style-fix": "stylelint \"src/**/*.scss\" --syntax scss --fix"
"lint:style-fix": "stylelint \"src/**/*.scss\" --syntax scss --fix",
"test": "cp ./sample.babelrc .babelrc && jest"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -59,6 +60,7 @@
"at-ui-style": "^1.5.1",
"autoprefixer": "^9.0.2",
"babel-eslint": "^8.2.3",
"babel-jest": "^23.4.2",
"babel-loader": "^8.0.0-beta.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-class-properties": "^6.24.1",
Expand Down Expand Up @@ -86,12 +88,14 @@
"html-webpack-plugin": "^3.2.0",
"html-withimg-loader": "^0.1.16",
"husky": "^1.0.0-rc.13",
"jest": "^23.5.0",
"json-loader": "^0.5.7",
"lint-staged": "^7.2.0",
"loader-utils": "^1.1.0",
"markdown-it": "^8.4.2",
"markdown-it-container": "^2.0.0",
"markdown-it-react-loader": "0.0.9",
"nerv-test-utils": "^1.3.2",
"node-fs-extra": "^0.8.2",
"ora": "^3.0.0",
"postcss": "^7.0.2",
Expand Down
22 changes: 22 additions & 0 deletions sample.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"presets": [
[
"@babel/env",
{
"spec": true,
"useBuiltIns": false
}
]
],
"plugins": [
[
"@babel/plugin-transform-react-jsx",
{
"pragma": "Nerv.createElement"
}
],
[
"@babel/plugin-proposal-object-rest-spread"
]
]
}
11 changes: 11 additions & 0 deletions src/components/input/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Nerv from 'nervjs'
import { renderIntoDocument } from 'nerv-test-utils'
import AtInput from '../../../.temp/components/input/index'


describe('Input', () => {
it('render Input', () => {
const component = renderIntoDocument(<AtInput></AtInput>)
expect(component.props.disabled).toBeFalsy()
})
})

0 comments on commit 2f523d0

Please sign in to comment.