【发布时间】:2014-04-02 13:38:35
【问题描述】:
我正在尝试存根我的猫鼬模型,特别是猫鼬的findById 方法
当 findById 使用 'abc123' 调用时,我正在尝试让 mongoose 返回指定的数据
这是我目前所拥有的:
require('../../model/account');
sinon = require('sinon'),
mongoose = require('mongoose'),
accountStub = sinon.stub(mongoose.model('Account').prototype, 'findById');
controller = require('../../controllers/account');
describe('Account Controller', function() {
beforeEach(function(){
accountStub.withArgs('abc123')
.returns({'_id': 'abc123', 'name': 'Account Name'});
});
describe('account id supplied in querystring', function(){
it('should retrieve acconunt and return to view', function(){
var req = {query: {accountId: 'abc123'}};
var res = {render: function(){}};
controller.index(req, res);
//asserts would go here
});
});
我的问题是运行 mocha 时出现以下异常
TypeError: 试图将未定义的属性 findById 包装为函数
我做错了什么?
【问题讨论】:
标签: node.js mongoose mocha.js sinon