reactjs - cypress - TypeError 无法设置未定义的属性“状态”
问题描述
每次我TypeError cannot set property 'status' of undefined
在不同的地方出错时,我都会尝试在我的 UI 测试中使用 cypress
describe('cats app', () => {
beforeEach(() => {
// Cypress starts out with a blank slate for each test
// so we must tell it to visit our website with the `cy.visit()` command.
// Since we want to visit the same URL at the start of all our tests,
// we include it in our beforeEach function so that it runs before each test
cy.visit(Cypress.env('host'))
})
it('login to cats', () => {
// clear local storage
cy.clearLocalStorage()
cy.get('#email').focus().type(Cypress.env('email'))
.should('have.value', Cypress.env('email'))
cy.screenshot("login-email")
cy.get('#password').focus().type(Cypress.env('password'))
.should('have.value', Cypress.env('password'))
cy.screenshot("login-password")
cy.get("#login").click({force: true})
// to ensure login is working
cy.get("#TicketsNav").should('be.visible')
cy.screenshot("TicketsNav")
})
})
我试图通过添加和使用这些命令来处理这个问题,因为它大部分时间都在打字时发生
Cypress.Commands.add(
'paste',
{
prevSubject: true,
element: true,
},
($element, text) => {
const subString = text.substr(0, text.length - 1);
const lastChar = text.slice(-1);
cy.get($element)
.click()
.then(() => {
$element.text(subString);
$element.val(subString);
cy.get($element).type(lastChar);
});
}
);
Cypress.Commands.overwrite('type', (originalFn, subject, text, options = {}) => {
options.delay = 20
return originalFn(subject, text, options)
})
另外,我试图强制使用 chrome 浏览器
cypress run --browser chrome
但如果不同的地方,我仍然会收到该错误
解决方案
推荐阅读
- node.js - 使用 docker-compose up 启动交互式 node.js CLI 应用程序
- javascript - 如何取消 QDate 选择?
- wordpress - 通过单击变体图像 Woocommerce 更改产品变体
- reactjs - React 条件格式三元
- java - 在循环中仅显示偶数,并添加偶数
- r - 用 NA 替换 COL2 中的行值,其中其他 COL3 值是 R 中的 NA
- python - 多处理代码不产生结果
- c# - 用 new string("...".ToCharArray()) 初始化一个字符串
- sql - 按 id 值计算多个单元格的最佳方法
- c++ - 无法理解 C++ 中的语法错误