Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
which data type to use to expect date value in jest

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?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!