使用赛普拉斯测试重定向到新路由

SeanPlusPlus:

我正在使用赛普拉斯来测试我的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?
  })
})

如评论所示,我不确定如何测试重定向到新路由是否有效。我可以在浏览器模拟中看到重定向有效,我只想为此添加一个测试。

谢谢!!!

詹妮弗·谢汉(Jennifer Shehane):

您需要做的是断言URL处于预期状态。

赛普拉斯中有许多命令可用于对URL进行断言。具体来说,cy.url()cy.location()cy.hash()可满足您的要求。可能是您的用例的最佳示例是:

cy.location('pathname').should('eq', '/newthing/:id')

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章