前言
本系列内容基本上按照官网的示例来讲解如何入门。
匹配器
首先讲匹配器,是单元测试最基础的部分,一般称为断言,如:assert,tap,chai,should等断言库。Jest内置了断言库,正式场景中不需引入断言库。
我们从基本类型讲起,
字符串
1  | it('"" toBe ""', () => {  | 
数字
1  | it('12 toBe 12', () => {  | 
数组
1  | test('[1,2,3,4,500] not toBe [1,2,3,4,500]', () => {  | 
布尔
1  | it('false toBeFalsy', () => {  | 
函数
1  | function sum(a) {  | 
对象
1  | it('{hello: "world"} toHaveProperty hello', () => {  | 
其他
1  | it('undefined toBeUndefined', () => {  | 
小结
以上总的讲述了Expect基本的使用API,接下来讲一讲另一个重要的方法mock。