Cypress 断言有.length;greaterThan number 错误

r3p*_*ica 5 cypress

我是 Cypress 的新手,我编写了一个简单的测试:

/// <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');
            });
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

一切正常,直到这一行cy.get('[data-cy=data-table-row]').should('have.length.greaterThan', '50');抛出此错误:

在此输入图像描述

有谁知道为什么会发生这种情况?

小智 5

错误消息说上面的参数必须是数字,尝试一下

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

为什么字符串参数在这里起作用?

cy.get('[data-cy=data-table-row]').should('have.length', '25');
Run Code Online (Sandbox Code Playgroud)

我的猜测是Javascript正在将长度参数的类型强制为字符串并且'25' === '25'是true,但是在greaterThan比较中'100' > '50'是false。