I'm testing all the links on a page but I only want a partial match.
I can test the full href like this
cy.visit('/');
cy.get('.class').find('a').should("have.attr", "href", "/123/456");
but I want to test the string partially, for example /456. I tried .contains() but it doesn't work.
You could use include,
cy.get('.class').find('a')
  .should('have.attr', 'href')
  .and('include', '/456');
or you can switch the subject
cy.get('.class').find('a')
  .invoke('attr', 'href')
  .should('contain', '/456');
or a longer version using jquery
cy.get('.class').find('a')
  .should('have.attr', 'href')
  .then(href => {
    expect(href.endsWith('/456')).to.be.true;
  });
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With