노드 js 코드 테스트에 도움이 필요합니다. 나는 mocha와 supertest를 사용하고 있으며 내 테스트의 제목과 같은 오류가 계속 발생합니다. 또한 mongoose를 사용하여 mongo 서버에 연결하고 테스트를 실행하기 전에 몇 가지 게스트 개체를 추가합니다. 나는 이것에 대해 이틀 동안 난처 해 졌으므로 어떤 도움을 주시면 감사하겠습니다.
다음은 테스트 오류입니다.
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)
}
});
});
});
그것을 조사한 후 오류 메시지가 나에게 야생 거위 추적을 보내고 있었고 서버를 내 보내지 않았습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다