Cypress assertions have.length;greaterThan number error

Viewed 1319

I am new to Cypress and I have written a simple test:

/// <reference types="Cypress" />

describe('brand workflow', () => {
    it('List brands', () => {
        cy.login().then(() => {
            cy.visit('/brands');

            cy.listBrands().then(() => {
                // TODO: Test the table functions

                cy.get('[data-cy=data-table-row]').should('have.length', '25');
                cy.contains('[data-cy=pagination]', '50').click();

                cy.get('[data-cy=data-table-row]').should('have.length', '50');
                cy.contains('[data-cy=pagination]', 'All').click();

                cy.get('[data-cy=data-table-row]').should('have.length.greaterThan', '50');
            });
        });
    });
});

Everything works up to this line cy.get('[data-cy=data-table-row]').should('have.length.greaterThan', '50'); which throws this error:

enter image description here

Does anyone know why this is happening?

1 Answers

The error message says the argument above must be a number, try

cy.get('[data-cy=data-table-row]').should('have.length.greaterThan', 50);

Why does a string parameter work here?

cy.get('[data-cy=data-table-row]').should('have.length', '25');

My guess is Javascript is coercing the type of the length parameter to be a string and '25' === '25' is true, but in the greaterThan comparison '100' > '50' is false.

Related