Problem during testing nodejs code with mocha

Problem during testing nodejs code with mocha
0

#1

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”:

 [email protected] 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;

#2

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

I’m a bit confused because your terminal output doesn’t seem to match the code you’ve supplied. Per the terminal, the test that’s running is “Nesting Records - Add a book to an author”:

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.

The test where you create a record should be fine, but check around your project and make sure you’ve accounted for all test files.


#3

Ok. Thank you, sir, but no one replied on my problem till now