小编Fla*_*hed的帖子

Cypress:存根打开窗口

在我的应用程序中有一个推荐列表,单击该列表会打开一个带有动态地址的新窗口:

$window.open(_shopURL, '_blank');
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试存根 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')
})
Run Code Online (Sandbox Code Playgroud)

但它总是打开新选项卡并且日志是错误的: Cypress:stub open window

有人知道为什么它不起作用吗?干杯!

javascript testing stub window.open cypress

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

cypress ×1

javascript ×1

stub ×1

testing ×1

window.open ×1