【问题标题】:Why is should.be.type() failing with "TypeError: (intermediate value).should.be.type is not a function"为什么 should.be.type() 因“TypeError: (intermediate value).should.be.type is not a function”而失败
【发布时间】:2016-05-25 18:01:53
【问题描述】:

我不明白为什么以下测试因错误而失败:

TypeError:(中间值).should.be.type 不是函数

describe('#Option object', function() {
    it('returns value as whatever type was passed to the constructor', function() {
        var o = function() {
            this.getValue = function() {
                return new Date();
            }
        };

        var i = new o();
        i.getValue().should.be.type('Date');
    })
});

我已经阅读了 [大部分] Should.js documentation,但我一定遗漏了一些东西。谁能告诉我我的测试出了什么问题?

【问题讨论】:

    标签: should.js


    【解决方案1】:

    其实只有一件事错了。您阅读的不是 should.js 文档,而是 unit.js 文档——它根本与 should.js 无关。 正确link。 正确的代码是:

    i.getValue().should.be.instanceOf(Date);
    

    i.getValue().should.be.Date();
    

    【讨论】:

      猜你喜欢
      • 2021-12-16
      • 1970-01-01
      • 2021-08-13
      • 1970-01-01
      • 2023-01-16
      • 2021-08-23
      相关资源
      最近更新 更多