jasmine

用jasmine做js单元测试。

安装

安装jasmine

npm i jasmine --save-dev

安装jasmine reporter

npm install jasmine-spec-reporter --save-dev

总命令:

npm install jasmine jasmine-spec-reporter babel-preset-es2015 babel-preset-stage-2 --save-dev

初始化

  1. 进入项目目录,输入
jasmine init
  1. 配置jasmine reporter,在项目目录下'spec/helper'下新建文件‘reporter.js’,里面的内容为:
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;

jasmine.getEnv().clearReporters();               // remove default reporter logs
jasmine.getEnv().addReporter(new SpecReporter({  // add jasmine-spec-reporter
  spec: {
    displayPending: true
  }
}));

测试

jasmine

建议

命名规范:测试文件目录命名与要测试的源码文件目录一致,测试文件命名在与源码文件一致的基础上,中间多加".spec",如

//源码文件名为:play.js
//测试文件名为:play.spec.js

附录

jasmine官方文档
官方英文:https://jasmine.github.io/api/2.6/
非官方中文(v2.1):https://yq.aliyun.com/articles/53426

你可能感兴趣的:(jasmine)