我试图模仿YouTube教程中的Cypress 拦截,但出于某种原因,我的方法不起作用.
下面是与教程相同的代码
it.only('test api with simple intercept stubbing', () => {
cy.visit('https://dummyapi.io/explorer');
cy.intercept({
path: 'data/v1/post/60d21af267d0d8992e610b8d/comment?limit=10'
}).as('comments')
cy.get('.flex > :nth-child(5)').click();
cy.wait('@comments').then(intercept => {
cy.log(JSON.stringify(intercept.response.body));
expect(intercept.response.body.limit).equal(10)
})
})
查看Cypress调试控制台,我实际上可以看到被单击的Comments元素,但它只是挂在Cy.等待
所以它会导航到页面,点击‘ comments ’,然后它就会挂在cy.Wait上,永远不会断言一个成功的GET.任何帮助都将不胜感激.