@rockerjs/tsunit

1.0.1 • Public • Published

基于decorator和mocha的单元测试框架

使用方式

  1. 安装npm包 npm install --save-dev @vdian/deco-mocha

  2. 通过npm script启动

{
     "scripts":{
         "test": "deco"
     }
}
  1. 写单测

在顶级目录创建一个test文件夹,在test文件中新建一个测试文件以*.spec.ts结尾. 开始写单测吧! 我们来完成一个简单的Hello world。

import  {contextConfiguration, Test, run, OnlyRun, Describe, before, after} from '@vdian/deco-mocha'
import * as chai from 'chai'
import * as path from 'path'

const expect = chai.expect

//contextConfiguration的参数为项目启动点的绝对路径
@contextConfiguration(path.resolve(__dirname,'../start'))
@Describe('测试Hello world')
class Helloworld {
    
    @Test('这是我的第一个测试')
    async firstTest(){
        console.log('Hello world');
        expect('Hello world').to.equal('Hello world');
    }
}

run(new Helloworld())

接下来运行npm test开始单元测试吧!

API DOCS

  • 基本API
    • run:运行测试实例
  • 装饰器
    • 类装饰器
      • contextConfiguration:参数为全局项目入口的绝对路径,用来注入项目环境
      • Describe:参数为此测试套件的描述,用来显示在报告中
    • 方法装饰器
      • Test:参数为此测试用例的描述,用来显示在报告中
      • before:所有测试用例之前执行一次函数
      • after:所有测试用例之后执行一次函数
      • beforeEach:每个测试用例执行之前都执行一次此函数
      • afterEach:每个测试用例执行之后都执行一次此函数
      • OnlyRun:此测试套件中仅执行此函数

TODO

-[] 更好的输出 -[] 支持流程控制decorator done -[] 更好的代码扩展性 done -[] 提交代码前的单测检验

Readme

Keywords

none

Package Sidebar

Install

npm i @rockerjs/tsunit

Weekly Downloads

2

Version

1.0.1

License

ISC

Unpacked Size

20.4 kB

Total Files

13

Last publish

Collaborators

  • flyseamomo001
  • royalrover
  • zjutkzwayne