@jspie

Как исправить ошибку при проверки POST через chai?

models/note.js
import mongoose from 'mongoose'

const Schema = mongoose.Schema;

const NoteSchema = new Schema({
	title: {type: String, required: true},
	description: {type: String, required: true},
	color:{type: String},
	createAt:{type: Date, required: true},
	author: {type: String, required:true}

}, {collection:'notes'});

mongoose.model('note', NoteSchema);

../Notedb.js
export const createNote = (data) =>{
	const note = new Note({
		title: data.title,
		description: data.description,
		color: data.color,
		createAt: new Date(),
		author: data.author
	});
	return note.save();
}

../noteApi
const router = express.Router();

router.post('/add', (req, res, next)=>{
	return noteDb.createNote(req.body)
		.then((done)=>{
			res.json(done);
		})
		.catch((err)=>{
			res.status(500).send();
		});
});


..Test/note.js
describe('/POST note add' , ()=>{
		it('it should POST test', (done)=>{
			let _note = {
				title: "Test note POST!",
				description: "This is test for note api",
				color: "yellow",
				author: "admin"
			}
			chai.request(server)
			.post('/add')
			.send(_note)
			.end((err, res)=>{
				res.should.have.status(200);
				res.body.should.be.a('object');
				//res.body.book.should.have.property('title');
				done();
			});
		});
	})


При тестировании вылетает такая вот ошибка: Timeout of 10000ms exceeded. For async tests and hook...
  • Вопрос задан
  • 265 просмотров
Пригласить эксперта
Ответы на вопрос 1
vahe_2000
@vahe_2000
По умолчанию тесты мокко имеют 2 секунды тайм-аута это означает, что тест должен быть завершен в течение 2 секунд. Вы можете увеличить (в miliiseconds) следующим образом: this.timeout(5000); Этот тест может занять до 5 секунд.попробуйте.mochajs.org/#asynchronous-code
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы