首页 > 解决方案 > 推荐如何在 Cypress 中使用断言

问题描述

您如何在项目中使用 Cypress 中的断言?在同一步骤 (it()) 或不同 (it()) 中执行步骤和断言?

1:

describe('test', ()=> {
    it('clicks on button "Add new user"', ()=> {
        // click action
        
        // assert (should()) modal to add new user is opened
    })
})

或者

2:

describe('test', ()=> {
    it('clicks on button "Add new user"', ()=> {
        // click action
    })
    
    it('Expect: modal should be opened', ()=> {
        // assert (should()) modal to add new user is opened
    })
})

在量角器中,我使用过没有。1,在同一个 it() 中使用 action 方法和 expect 方法,但是在 Cypress 中,您不能为 should() 断言添加自定义消息,以准确查看失败的原因。(例如'模态应该打开')

谢谢!

标签: cypress

解决方案


推荐阅读