Cypress split string for test

Viewed 6671

i need to parse a string in cypress. i am trying to grab a piece of string with the methods provided by javascript. but it doesn't work gives me an error:

type i have this string:

text2 = "change status id 423 in Cult"
text1 = 423

var id = text2.split (' ')
expect (text1).to.eq(id[3])

how can i do such a thing in cypress. I should take part of a string and compare it but with the split method it gives me an error

below the error returned: enter image description here

1 Answers

You have to use then() instead of should() -

cy.get('p.text-lg').invoke('text').then((text) => {
    var splitText = text.split(' ')[5]
    expect(splitText).to.equal(291)
})
Related