我一直在搜索,找不到一个简单的sinon示例(断言?),检查函数.doSomething
是否存在。
var sinon = require('sinon');
var myModule = require('my-module');
describe('myModule', function () {
it('has a function .doSomething', function () {
// check whether typeof myModule.doSomething === 'function'
});
});
检查此功能是否存在的正确方法是什么?
答案 0 :(得分:2)
sinon.assert.match(myModule.doSomething, sinon.match.func);
或
sinon.assert.match(typeof myModule.doSomething, "function");
答案 1 :(得分:0)
这应该使用断言库,而不是sinon(这是一个存根/模拟库)。
Chai是与mocha一起使用的流行选项:
var expect = require('chai').expect;
var myModule = require('my-module');
describe('myModule', function () {
it('has a function .doSomething', function () {
expect(myModule.doSomething).to.be.a('function')
});
});