【发布时间】:2019-01-15 18:58:23
【问题描述】:
在我的应用中有一个推荐列表,点击它会打开一个带有动态地址的新窗口:
$window.open(_shopURL, '_blank');
现在我正在尝试存根 windows.open 事件,如 https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/stubbing-spying__window/cypress/integration/window-stubbing.spec.js 所示
Cypress.on('window:before:load', (win) => {
win.open = cy.stub().as('windowOpen')
})
describe('Shop integration', () => {
beforeEach(function () {
cy.visitHome(countryCode, resellerId)
})
it('can stub the window open event', function () {
cy.get(`.recommendations-list .recommendations-cover:nth-of-type(1)`)
.click()
cy.get('@windowOpen').should('be.calledWith', 'page1.html')
})
但它总是打开新标签并且日志是错误的: Cypress: stub open window
有人知道为什么它不起作用吗? 干杯!
【问题讨论】:
-
嗨,我正在尝试做完全相同的事情,但到目前为止没有成功。您找到解决此问题的方法了吗?
标签: javascript testing window.open stub cypress