This would be silliest question which I am asking here. I was going through Cypress automation and was working on one of the scenario.
I wanted to verify whether the date is matching or containing the date or not.
System date - 11/30/2021 06:18:33 PM and derived application date - 11/30/2021 6:18:38
How can I match and assert this using Cypress?
expect('11/30/2021 06:18:33 PM').to.have.string('11/30/2021 6:18:38');
I am getting below error :-
AssertionError
expected '11/30/2021 06:18:33 PM' to contain '11/30/2021 6:18:38'
You can use to.include, something like:
expect('11/30/2021 06:18:33 PM').to.include('11/30/2021 06:18:33')
Or if you just want to match the dates, you can do something like this. Using split we are extracting just the date and asserting it.
expect('11/30/2021 06:18:33 PM'.split(' ')[0]).to.equal(
'11/30/2021 06:18:33'.split(' ')[0]
)