Using sinon with mocha & findById - TypeError: Attempted to wrap undefined property findById as function

1,880 views
Skip to first unread message

Alex Brown

unread,
Mar 2, 2014, 5:21:51 PM3/2/14
to sin...@googlegroups.com

I'm having a similar problem to the one posted here

I have also posted this on stack overflow

Here's what I have:

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
            });
    });

My problem is that I am getting the following exception when running mocha

TypeError: Attempted to wrap undefined property findById as function

What am I doing wrong?


Reply all
Reply to author
Forward
0 new messages