-
toBe
匹配器
案例:
test('测试对象相等',()=>{
except(10).toBe(10);
})
-
toEqual
匹配器
案例:
test('测试对象内容相等',()=>{
const a={one:1};
except(a).toEqual({one:1});
})
-
toBeNull
匹配器
案例:
test('测试对象为null',()=>{
const a=null;
except(a).toBeNull();
})
-
toBeUndefined
匹配器
案例:
test('测试对象未定义',()=>{
const a=undefined;
except(a).toBeUndefined();
})
-
toBeDefined
匹配器
案例:
test('测试对象未定义',()=>{
const a=123;
except(a).toBeDefined();
})
-
toBeTruth
匹配器
案例:
test('测试对象为真',()=>{
const a=1;
except(a).toBeTruth();
})
-
toBeFalsy
匹配器
案例:
test('测试对象为假',()=>{
const a=0;
except(a).toBeFalsy();
})
-
not
匹配器
案例:
test('测试对象为真',()=>{
const a=1;
except(a).not.toBeFalsy();
})
-
toBeGreaterThan
匹配器
案例:
test('测试比某个数大',()=>{
const a=2;
except(a).toBeGreaterThan(1);
})
-
toBeLessThan
匹配器
案例:
test('测试比某个数小',()=>{
const a=1;
except(a).toBeLessThan(2);
})
-
toBeGreaterThanOrEqual
匹配器
案例:
test('测试大于等于某个数',()=>{
const a=2;
except(a).toBeGreaterThanOrEqual(1);
})
-
toBeLessThanOrEqual
匹配器
案例:
test('测试小于等于某个数',()=>{
const a=1;
except(a).toBeLessThanOrEqual(2);
})
-
toBeCloseTo
匹配器
案例:
test('测试浮点数计算结果',()=>{
const a=0.1;
const b=0.2;
except(a+b).toBeCloseTo(0.3);
})
-
toMatch
匹配器
案例:
test('测试字符串匹配',()=>{
const str='asdfghjk';
except(str).toMatch(asd);//可以是字符串也可以是正则表达式
})
-
toContain
匹配器
案例:
test('测试数组包含某元素',()=>{
const arr=[1,2,3];
except(arr).toContain(1);
})
-
tothrow
匹配器
案例:
const throwfunc=()=>{
throw new Error('this is a error');
}
test('测试异常',()=>{
except(throwfunc).toThrow();
})