1.0.1 • Published 6 years ago

wepy-jest v1.0.1

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

wepy-jest

使用 Jest 对 WePY 添加单元测试功能,目前只会读取 script 的内容和 script 中的 src 属性。lang 属性目前还不支持,也就是说只支持 babel 一种,当然,这是暂时的。

安装

npm i wepy-jest -D

修改 package.json

"scripts": {
  ...
  "test": "jest ./src/**/*.spec.js",
  "test:watch": "jest ./src/**/*.spec.js --watch"
},
...
"babel": {
  "presets": [
    "env"
  ]
},
"jest": {
  "moduleFileExtensions": [
    "js",
    "wpy"
  ],
  "transform": {
    "^.+\\.js$": "<rootDir>/node_modules/babel-jest",
    ".*\\.(wpy)$": "<rootDir>/node_modules/wepy-jest"
  }
},
...

编写测试

创建 index.spec.js

import Index from './IndexPage.wpy'

test('two plus two is four', () => {
  expect(2 + 2).toBe(4);
});

test('index.data.a will be 1', () => {
  const index = new IndexPage();
  expect(index.data.a).toBe(1);
});

运行测试

npm test