【问题标题】:Mocha Chai Expect. How can i verify that A class is exists?摩卡柴期待。如何验证 A 类是否存在?
【发布时间】:2021-03-16 07:44:46
【问题描述】:

如标题所述。请问这个场景的测试代码怎么写?

示例...我有一个像这样的课程。

let ABC = function()
{
    this.title="sample"
};

问题是我如何使用 chai expect 来检查 ABC 类的存在?

期望 chai 做这样的事情吗? Expect(ABC).to.be.a.class

【问题讨论】:

    标签: javascript node.js testing mocha.js chai


    【解决方案1】:

    我不确定你是否已经回答了这个问题,但我有同样的问题,我刚刚发现

    • 所以在需要 chai 和期望 API 之后
    • 在需要您的班级所在的文件并设置您的测试之后
    • 您可以确保:
        1. 这是一个带有.to.be.a('function');的函数
        1. 检查它是否是您的类的实例 expect(className).to.be.an.instance.of(ClassName);
    const chai = require('chai');
    const expect = chai.expect;
    const Card = require('../src/Card');
    
    describe('Card', function () {
        it.skip('should be a function', function () {
            const card = new Card();
            expect(Card).to.be.a('function');
        });
    
        it.skip('should be an instance of Card', function () {
            const card = new Card();
            expect(card).to.be.an.instanceof(Card);
        })
    })
    

    【讨论】:

      猜你喜欢
      • 2015-05-01
      • 2018-05-24
      • 1970-01-01
      • 1970-01-01
      • 2020-07-27
      • 2019-11-15
      • 1970-01-01
      • 2016-03-12
      • 2019-11-25
      相关资源
      最近更新 更多