jeudi 26 mars 2015

Mocha test case with mongoose findOne returning null data

I recently started writing test cases for my node app using Mocha frame work , but got stuck in very irritating error when I am trying mongoose findOne function in my test case :


My test case is basically for an api which fetch me a single record from my collection usine mongoose.load function ,my code is somthing like this : -



//retrive by id
it("function #findOne", function(done) {
Books.load(book._id, function(err, data) {
expect(err).to.be(null);
expect(data.name).to.equal('Book Name');
expect(data.price).to.equal(45);
expect(data.description).to.equal('Book Description');
expect(data.belongTo.length).to.not.equal(0);
expect(data.created.length).to.not.equal(0);
done();
});
});


my function is returning me both err, data as null . So my test case is getting fail with an error :



Uncaught TypeError: Cannot read property 'name' of null


sorry for being a newbie , and thank you so much in advance .


Aucun commentaire:

Enregistrer un commentaire