Мне нужна помощь с тестированием кода js узла. Я использую mocha и supertest и получаю сообщение об ошибке, аналогичное названию в моем тесте. Я также использую mongoose для подключения к серверу mongo, и перед запуском тестов добавляю несколько гостевых объектов. Я был озадачен этим в течение 2 дней, поэтому любая помощь приветствуется.
Вот ошибка теста
0 passing (96ms)
1 failing
1) Guestss
GET /guests
should GET all the guests:
TypeError: Cannot read property 'address' of undefined
at Test.serverAddress (node_modules/supertest/lib/test.js:55:18)
at new Test (node_modules/supertest/lib/test.js:36:12)
at Object.get (node_modules/supertest/index.js:25:14)
at Context.<anonymous> (test/functional/api/guestTest.js:95:18)
Вот код теста
describe("GET /guests", () => {
it("should GET all the guests", done => {
console.log("before");
request(server)
.get("/guests")
.set("Accept", "application/json")
.expect("Content-Type", /json/)
.expect(200)
.end((err, res) => {
try {
expect(res.body).to.be.a("array");
expect(res.body.length).to.equal(2);
let result = _.map(res.body, guest => {
return {
name: guest.name,
people: guest.people,
roomno: guest.roomno,
breakfast: guest.breakfast,
roomtype: guest.roomtype,
check: guest.check
}
});
expect(result).to.deep.include({
name: "Tommy blue",
people: 5,
roomno: 0,
breakfast: true,
roomtype: "family",
check: "waiting"
});
expect(result).to.deep.include({
name: "Chad Warren",
people: 2,
roomno: 45,
breakfast: true,
roomtype: "double",
check: "in"
});
done()
} catch (e) {
done(e)
}
});
});
});