Hi there.
I’m facing a problem while I test the code by mocha.
This is the error which I get in the terminal after typing “npm run”:
wael@1.0.0 test /media/wael/Series+Films+Orgs/DEADMAN/Web-Design/Node.js/Author
mocha
Nesting Records
1) Add a book to an author
0 passing (2s)
1 failing
1) Nesting Records
Add a book to an author:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
npm ERR! Test failed. See above for more details.
And this is the test.js file content:
var mongoose = require('mongoose');
var Author = require('./Author');
var assert = require('assert')
describe('Nesting Records', function(){
it('Creates New Record', function(done){
var pat = new Author({
name: 'Patrison Man',
books: [{title: 'The Wind', pages: 400}]
});
pat.save().then(function(){
Author.findOne({name: 'Patrison Man'}).then(function(record){
assert(record.books.length === 1);
done()
});
});
});
});
Finally this is the author.js file:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
//Create Schema
var bookSchema = new Schema ({
title: String,
pages: Number
});
var authorSchema = new Schema ({
name: String,
age: Number,
Books: [bookSchema]
});
var Author = mongoose.model('author', authorSchema);
module.exports = Author;