I am struggling to validate the titles for a certain component. Here is my specific Cypress code snippet:
it('Confirming the correctness of all tile titles', () => {
cy.get('.bms-scoreboard__game-tile')
.each(($el) => {
if($el.hasClass('bms-scoreboard__game-tile--cancelled')) {
$el.get('.bms-scoreboard__game-tile-status--cancelled')
.invoke('text')
.then((text) => {
expect(text).equals('Cancelled')
})
} else if($el.hasClass('bms-scoreboard__game-tile--pre-game')) {
$el.get('.bms-scoreboard__game-time--en')
.invoke('text')
.then((text) => {
const gameTime = text.split(" ").pop()
expect(['AM', 'PM']).to.include(gameTime)
})
} else if($el.hasClass('bms-scoreboard__game-tile--final')) {
$el.get('.bms-scoreboard__game-time--en')
.invoke('text')
.then((text) => {
const finalTitle = text.trim()
expect(finalTitle).to.be.oneOf(['Final','Final (OT)'])
})
} else if($el.hasClass('bms-scoreboard__game-tile--ongoing')) {
$el.get('.bms-scoreboard__game-time--en')
.invoke('text')
.then((text) => {
const ongoingTitle = text.trim()
expect(ongoingTitle).equals('Ongoing')
})
}
})
})
An error message pops up saying: 'Cannot read properties of undefined (reading 'invoke')'.
The test runs smoothly when just using the if block alone.