Why Am I getting "TypeError: Cannot read property 'restore' of undefined" when stubbing mongoose with sinon.js
The Problem was that I was trying to stub the Prototype as directed by alot of snippets I found online so I changed
var stub = sinon.stub(PeopleProvider.Model.prototype, 'find', somefunction);
to
var stub = sinon.stub(PeopleProvider.Model, 'find', somefunction);
I also realized after fixing this error that I also was missing my callback so here is the full changes for the test:
it("Test: stubbing find for getAllPeople", function (done) { var stub = sinon.stub(PeopleProvider.model, 'find', function (callback) { var results = [{ name: "John", addresses: ["abc", "123", "xyz"] }, { name: "Jane", addresses: ["123 fake st", "somewhereville"] }, { name: "Joe", addresses: ["someplace", "overthere", "here"] }]; callback(null, results); }); PeopleProvider.getAllPeople(function (error, data) { expect(data instanceof Array).to.equal(true); expect(data.length).to.equal(3); expect(data[0].name).to.equal("John"); expect(data[0].addresses.length).to.equal(3); expect(data[0].addresses[0]).to.equal("abc"); expect(data[1].name).to.equal("Jane"); expect(data[1].addresses.length).to.equal(2); expect(data[1].addresses[0]).to.equal("123 fake st"); expect(data[2].name).to.equal("Joe"); expect(data[2].addresses.length).to.equal(3); expect(data[2].addresses[0]).to.equal("someplace"); done(); });});