我正在使用Cypress来测试我的Web应用程序 .
此代码段目前有效并将提交新内容:
describe('The Create Page', () => {
it('successfully creates a thing', () => {
cy.visit('/create')
cy.get('input[name=description]').type('Hello World')
cy.get('button#submit')
.click()
// After POST'ing this data via AJAX, the web app then
// receives the id of the new thing that was just created
// and redirects the user to /newthing/:id
// How do I test that this redirection worked?
})
})
正如评论所示,我不知道如何测试重定向到新路由是否有效 . 我可以在浏览器模拟中看到重定向工作,我只是想为它添加一个测试 .
谢谢!!!
1 回答
您需要做的是声明url处于预期状态 .
赛普拉斯有许多命令可用于对url进行断言 . 具体而言,cy.url(),cy.location()或
cy.hash()
可能符合您的要求 . 对您的用例来说,最好的例子可能是: