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:
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))
