Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  73] [ 7]  / answers: 1 / hits: 5464  / 2 Years ago, wed, december 22, 2021, 12:00:00

in my test


    it("should list all tickets", async () => {
const getTicket = await request(app)
.get("/v1/ticket")
.set("authorization", loginResponse.body.accessJWT);
console.log(getTicket.body.result);
console.log(getTicket.body.result[0].conversations);
expect(getTicket.body.result).toEqual(
expect.arrayContaining([
expect.objectContaining({
// _id: expect.any(String),
// status: "pending response",
openAt: expect.any(Date),
conversations: expect.arrayContaining([
expect.objectContaining({
// sender: expect.any(String),
msgAt: expect.any(String),
// message: expect.any(String),
}),
]),
}),
])
);
});

});


i am checking if the value of openAt and msgAt is a date value. But the date value is saved in the string form similar to


"msgAt": "2021-12-22T08:29:15.038Z",

How to check if the value of openAt will be a date saved in a string format?


More From » datetime

 Answers
5

You could probably just do the following:


expect(new Date(msgAt)).toBeInstanceOf(Date);

Converting the returned value to a Date and checking if it's a date. If the value is not convertible to date, test will fail.


[#566] Saturday, December 11, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradleymoisesy

Total Points: 121
Total Questions: 105
Total Answers: 95

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
bradleymoisesy questions
Tue, Jun 1, 21, 00:00, 3 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
Thu, Jan 16, 20, 00:00, 4 Years ago
;