@tool-developer/wx-unit

0.0.6-canary.6 • Public • Published

@tool-developer/wx-unit

微信小程序单元测试工具包。

用法

npm install --save-dev @tool-developer/wx-unit

or

yarn add -D @tool-developer/wx-unit
import unit from '@tool-developer/wx-unit'

操作步骤

  1. 项目初始化,并配置test scripts
npm init

package.json

"scripts": {
  "test": "jest"
},
  1. 安装jest,参考jest.
npm install -g jest
  1. 安装依赖和配置babel
npm install -D jest babel-jest babel-core @babel/preset-env @tool-developer/wx-unit

babel.config.js

module.exports = {
  presets: [['@babel/preset-env', {targets: {node: 'current'}}]]
};
  1. 创建jest.config.js, 并配置
jest --init

jest.config.js

  "verbose":true,
  "testEnvironment": "node",
  //测试前先启动环境依赖文件
  "setupFiles":['./test.js'],
  //需要编译node_modules时配置
  "transformIgnorePatterns": [
  ],
  //单测覆盖
  "coverageDirectory": "coverage",
  //单测覆盖忽略文件
  "coveragePathIgnorePatterns": [
    "./test.js"
  ],
  //测试路径忽略文件
  "testPathIgnorePatterns": [
    "./test.js"
  ],
  1. 在项目目录下创建test.js,这样:
import unit from '@tool-developer/wx-unit';

export default unit;
  1. 编写单元测试文件,具体参考jest document

  2. 运行

npm run test

Dependents (0)

Package Sidebar

Install

npm i @tool-developer/wx-unit

Weekly Downloads

0

Version

0.0.6-canary.6

License

MIT

Unpacked Size

37.1 kB

Total Files

10

Last publish

Collaborators

  • tooldeveloper