前端测试工具-摩卡(简单了解)
来源:互联网 发布:网络21健康行是传销吗 编辑:程序博客网 时间:2024/06/05 16:52
关于摩卡
mocha 2011年是目前现在最流行的javaScript测试框架。
测试框架就是运行测试的工具通过一系列的方法对javaScript应用进行测试保证代码的质量。
安装项目目录
- 全局安装 npm install mocha -g
- npm init
- npm install mocha –save-dev
- npm install chai –save-dev(断言库)
mocha声明周期函数
- before() 测试之前
- after() 测试之后
- beforeEach() 每条测试之后
- afterEach() 每条测试之后
describe("demo",function(){ describe("登录方法",function(){ before(function(){ console.log("测试之前") }) after(function(){ console.log("测试之后") }) beforeEach(function(){ console.log("每条测试之前") }) afterEach(function(){ console.log("每条测试之后") }) context("情景1的情况下",function(){ it("iphone手机测试",function(){ console.log("通过") }) it("oppo手机测试",function(){ console.log("通过") }) }) })})
assert 断言
说白了就是一些布尔表达式,通过启用或者禁用用于辅助验证的这段逻辑或者方法是否是正确的。
- 断言一段有两种:一种是直接返回布尔类型;一种通过true,或者false来throw
#
- 我们使用chai断言库
- 他是提供了三种分割的断言测试(assert should expect)
// assert 测试const chai = require('chai');const assert = chai.assert;describe("进行assert风格断言测试",function(){ it("进行assert测试",function(){ var value = "test" assert.typeOf(value,"string"); assert.equal(value,"test"); assert.lengthOf(value,4) })})
// shuold 风格测试const chai = require("chai");const should = chai.should();describe("should风格的测试",function(){ it("进行should测试",function(){ var value = "test"; value.should.be.a("string"); value.should.equal("test"); value.should.not.equal("tests"); value.should.have.length(4); })})
// expect 断言测试const chai = require('chai');const expect = chai.expect;describe("expect断言测试",function(){ it("expect",function(){ var value = 'test'; expect(value).to.be.a("string"); expect(value).to.equal("test"); expect(value).to.not.equal('tests'); expect(value).to.have.length('4'); })})
0 0
- 前端测试工具-摩卡(简单了解)
- 简单了解snapdragon的分析测试工具
- 前端测试工具
- 前端性能测试工具
- zmap 工具简单了解
- 了解 WS-I 测试工具
- JMeter 压力测试工具了解
- 性能测试知多少---了解前端性能
- 性能测试知多少---了解前端性能
- 性能测试知多少---了解前端性能
- 你需要了解的前端测试“金字塔”
- 你需要了解的前端测试“金字塔”
- 你需要了解的前端测试“金字塔”
- 前端开发测试工具汇总
- 前端开发、调试、测试工具
- 前端开发环境(开发,调试,测试工具)
- APP测试、WEB测试简单了解
- 20130320日报(前端了解)
- swagger ui和spring boot集成生成api文档
- 不同概率的抽奖
- php 分页类
- 推导相机变换矩阵
- 目前看到的最好的RNN、LSTM、GRU博客:Understanding LSTM Networks(翻译)
- 前端测试工具-摩卡(简单了解)
- web前端知识体系大全
- SpringMvc中表单标签的使用注意点
- 链表算法之k逆序
- Gson 解析工具封装
- expected at least 1 bean which qualifies as autowire candidate for this dependency.
- 解决eclipse中git插件中的cannot open git-upload-pack问题
- Android Intent 启动第三方程序
- 第143课:Spark面试经典系列之Reduce端OOM和shuffle file not found如何解决