vue-test-util一些笔记

JavaScript016

vue-test-util一些笔记,第1张

now using vuejs-cli !!!!--It's now recommended to scaffold your project with Vue CLI 3 which provides out-of-the-box configurations for unit testing.

01.已有方案

02.方便快速

03.借鉴参考

the official unit testing utility library for Vue.js

安装软件

基本结构

获取内容

用户交互

此处用户交互主要讲述如何模拟用户交互

异步操作

此处异步操作主要讲述如何模拟异步操作。

01.Knowing What to Test

02.Shallow Rendering

03.Asserting Emitted Events

04.Emitting Event from Child Component

05.Manipulating Component State

06.Mocking Props

07.Applying Global Plugins and Mixins

08.Mocking Injections

09.Stubbing components

10.Dealing with Routing

11.Detecting styles

用运行器

A test runner is a program that runs tests.

模拟浏端

running the tests in Node with a virtual browser environment using JSDOM

测试单组

一些测试单文件组件的示例

01. Testing Single-File Components with Jest

02. Testing Single-File Components with Mocha + webpack

03.Testing Single-File Components with Karma

开始搭建

哪些文件

01.By default, Jest will recursively pick up all files that have a .spec.js or .test.js extension in the entire project.

02.If this does not fit your needs, it's possible to change the testRegex

in the config section in the package.json file.

测覆盖率

单元示例

测试快照

testing-single-file-components-with-karma

vue-test-utils.guides.vuejs[p].

eddyerburgh.vue-test-utils-karma-example[p].github

vuejs.vue-test-utils-mocha-webpack-example[p].github

vuejs.vue-test-utils-jest-example[p].github

方法:获取page数据,看代码:var text=this.data.name  ,这样就获取到初始化的值

page({

data:{name:"test"},

showData:function(){

var text=this.data.name

}

})

示例如下:

util.js

//正则判断

function Regular(str, reg) {

if (reg.test(str))

return true

return false

}

//是否为中文

function IsChinese(str) {

var reg = /^[\u0391-\uFFE5]+$/

return Regular(str, reg)

}

module.exports = {

getRequestUrl: "http://localhost:59637",//获得接口地址

IsChinese: IsChinese,

}

//test.js

var util = require('../../utils/util.js')

Page({

onLoad: function () {

console.log("判断是否为中文:"+util.IsChinese('测试'))

console.log("输出接口url:"+util.getRequestUrl)

}

})