У меня есть следующий тест:
describe('GET /club/', async () => {
it('get all events by club', async () => {
const club = await clubDAO.create(clubParams);
const event = await eventDAO.create({
...baseEventParams,
name: 'In month',
date: '2020-01-01',
club: club
});
const resp = await http.get(`/api/event/club/${club._id}`);
isOk(resp);
const data = resp.body.data;
console.log("Original event is")
console.log(event)
console.log("Response event is ");
console.log(data)
data.should.have.length(1);
// event.id is of type ObjectId, data has string representation of ObjectId
// Used JSON.parse to be able to compare ObjectId and with the string representation successfully
data.should.deep.include(JSON.parse(JSON.stringify(event)))
});
});
Этот тест проверит, что data
(который содержит массив объектов Event) содержит созданное событие event
. Таким образом, data
должен содержать event
.
Выходные данные следующие:
Original event is
{
goingUsers: [],
_id: 5e8e5056fdcfc339c5e51e17,
name: 'In month',
location: 'Location',
major_of_interest: 'Computer Science',
description: 'This is an event',
date: 2020-01-01T00:00:00.000Z,
club: 5e8e5056fdcfc339c5e51e16,
__v: 0
}
Response event is
[
{
goingUsers: [],
_id: '5e8e5056fdcfc339c5e51e17',
name: 'In month',
location: 'Location',
major_of_interest: 'Computer Science',
description: 'This is an event',
date: '2020-01-01T00:00:00.000Z',
club: {
admins: [],
_id: '5e8e5056fdcfc339c5e51e16',
name: 'Club Club',
facebook_link: 'facebook',
description: 'This is a club',
category: 'Computer Science',
__v: 0
},
__v: 0
}
]
Итак, data
содержит event
, но поскольку информация в data
заполнил информацию (club
), затем тест не пройден. event
не имеет заполненного club
, но это по существу правильно (у него просто нет заполненной информации). Как я могу проверить это, игнорируя заполненную информацию о клубе.