vendredi 21 décembre 2018

Why is cypress timing out when evaluating this regex?

I'm new to cypress and am curious what I'm doing wrong.

I have a test which validates the contents of a table on a page. One of those columns contains a formatted date--the date can be off by a little bit, so I'm using a regex to validate it rather than a strict comparison.

The test looks something like this:

it.only('I can see the date',  ()=> {

    // Match dates like 'Dec. 21, 2018 at 1:12 pm'
    const approximateTime = new RegExp(Cypress.moment().format('MMM[\]. D, YYYY [at] h:[.. {a|p}m]'));

    cy.get('table.activity-log').within(() => {
        cy.get('tbody tr').eq(0).within(() => {
            cy.get('td').eq(0).invoke('text').should('match', approximateTime);
...

I'm running it against HTML and it matches the expected element, which looks something like:

<td>
    Dec. 21, 2018
    <span> at </span>
    1:12 pm
</td>

The test runs and times out while retrying:

AssertionError: expected 'Dec. 21, 2018 at 1:12 pm' to match /Dec. 21, 2018 at 1:.. {a|p}m/

Am I doing something wrong with the .invoke('text'), or elsewhere in the test?

Aucun commentaire:

Enregistrer un commentaire