Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Compare time stamps in Cypress

I want to check if part of the content of the input box contains the current YYMMDD HH. I don’t want to check MM and SS because this will be inaccurate taking into consideration the time passed to do the comparison. So, I did

  const dayjs = require('dayjs')
  companionPage.countNameInputBox().invoke('val').then((text) => {
   expect(text.trim()).to.have.text(dayjs().format('YYMMDD HH'))
  })

But I got:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I remove the comparison for MM and SS? and solve the above error?

>Solution :

As you will have always a fixed number (9) of characters in 230509 17, you can use .slice(0,9):

const dayjs = require('dayjs')
companionPage.countNameInputBox().invoke('val').then((text) => {
   expect(text.trim().slice(0,9)).to.have.text(dayjs().format('YYMMDD HH'))
})
console.log('230509 174301'.slice(0,9))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading