【发布时间】:2021-11-15 23:00:04
【问题描述】:
我有一个测试,它获取表格的元素并通过查看它们的内容是否相同来对抗它们,并且它有效:
cy.compareInputToText(
'app-myTable table tbody > :nth-child(1) > :nth-child(2) > input',
'app-myTable table tbody > :nth-child(1) > :nth-child(3)'
);
Cypress.Commands.add('compareInputToText', (inputSelector, textSelector) => {
cy.get(inputSelector)
.invoke('val')
.then(currentValue => {
cy.get(textSelector)
.should('have.text', currentValue);
});
});
问题是当我在要测试的组件中添加一个较长的
trim 尝试了各种解决方案,如下所示:
Cypress.Commands.add('compareInputToText', (inputSelector, textSelector) => {
cy.get(inputSelector)
.invoke('val')
.then(currentValue => {
cy.get(textSelector)
.should('have.text', currentValue!.toString.trim());
});
});
但它不起作用。 【问题讨论】:
错误:
错误:AssertionError: Timed out retrying after 4000ms: expected to have text '0.2', but the text is '0.2'
标签: unit-testing testing cypress e2e-testing cypress-component-test-runner