美文网首页
03|匹配器

03|匹配器

作者: 雪燃归来 | 来源:发表于2020-05-21 21:13 被阅读0次

一、持续监听

package.json

scripts:{
  "test":"jest --watchAll"
}

二、匹配器

1、 toBe 匹配器 matchers
test('测试10与10相匹配',() => {
     // expect(10).toBe(10)
    // const a = { one: 1}
    // expect(a).toBe({ one: 1})
})

test('测试对象内容相等',() => {
    const a = { one: 1}
    expect(a).toEqual({one: 1})
})

test('是否为null',() => {
    const a = null;
    expect(a).toBeNull()
})

// 真假相关
test('是否为null',() => {
    const a = null;
    expect(a).toBeNull()
})

test('toBeUndefined',() =>{
    const a = undefined
    expect(a).toBeUndefined();
})

test('toBeDefined匹配器',() => {
    const a = null;
    expect(a).toBeDefined()
})

test('toBeTruthy 匹配器', () => {
    const a = 1
    expect(a).toBeTruthy()
})

test('toBeFalsy 匹配器',() => {
    const a = null
    expect(a).toBeFalsy()
})

test('not 匹配器',() => {
    const a = 1;
    expect(a).not.toBeFalsy()
})

// 数字相关的
test('toBeGreaterThan',() => {
    const count = 10;
    expect(count).toBeGreaterThan(9)
})

test('toBeLessThan', () => {
    const count = 10;
    expect(count).toBeLessThan(11)
})
test('toBeGreaterThanOrEqual', () => {
    const count = 10;
    expect(count).toBeGreaterThanOrEqual(10)
})

test('toBeCloseTo', () => {
    const a = 0.1;
    const b = 0.2;
    expect(a+b).toBeCloseTo(0.3)
})

// 跟字符串相关的匹配器
test('toMatch', () => {
    const str = 'http://www.dell-lee.com'
    expect(str).toMatch(/dell/)
})

// 跟数组相关的匹配器
// array set
test('toContain', () => {
    const arr = ['dell', 'lee', 'imooc']
    const data = new Set(arr);
    // expect(data).toContain('dell')
    expect(arr).toContain('dell')
})


//异常
const throwNewErrorFunc = () => {
    throw new Error('this is a new error');
}
test('toThrow', () => {
    expect(throwNewErrorFunc).toThrow(/this is a new error/)
})

相关文章

  • 03|匹配器

    一、持续监听 package.json 二、匹配器

  • 设计模式 - 目录

    设计模式01 - 单例模式 设计模式02 - 工厂模式 设计模式03 - 建造者模式 设计模式04 - 适配器模式...

  • 【设计模式】适配器模式

    学习文章 iOS设计模式 - 适配器 适配器模式(Adapter):类适配器、对象适配器 类图 说明 类适配器: ...

  • ListView常用知识点归纳

    适配器 适配器实现过程:共3步:新建适配器-->添加数据源到适配器-->视图加载适配器 适配器的数据源:Array...

  • iOS设计模式 (五) 适配器模式

    适配器模式 iOS中的适配器模式,主要由目标协议,适配者,适配器三部分组成. 适配器模式分类 类适配器: 适配器是...

  • 设计模式-适配器

    适配器模式,目的是为了适配补偿,对于适配器模式,我们要学习的两种方式是类适配器和对象适配器。 类适配器 类适配器是...

  • Java设计模式(二)

    talk is cheap show me the code 适配器模式 类适配器模式 接口适配器模式 对象适配器...

  • 适配器模式

    目录 1、什么是适配器模式? 2、适配器模式结构? 3、如何实现适配器模式? 4、适配器模式的特点? 5、适配器模...

  • 适配器模式

    先直观感受下什么叫适配器 适配器模式有类的适配器模式和对象的适配器模式两种不同的形式。 类适配器模式 对象适配器模...

  • iOS 适配器模式

    适配器模式创建适配协议,创建抽象适配器类,创建类适配器/对象适配器。 应用,适用场景电源适配器,普通充电器(类适配...

网友评论

      本文标题:03|匹配器

      本文链接:https://www.haomeiwen.com/subject/zjztahtx.html