I'm testing a vue app which has a mixin that relies on a window method:
export default {
data () {
return {
aurora: window.Aurora || {}
}
},
methods: {
quickView () {
const hasQuickViewElement = document.querySelector('#product-quickview')
if (hasQuickViewElement && this.id && typeof this.aurora.quickview === 'function') {
this.aurora.quickview(this.id)
}
},
wishlist () {
if (this.id && typeof this.aurora.showOverlay === 'function') {
this.aurora.showOverlay('#add-shop-list', { prodId: this.id })
}
}
}
}
I'm trying to mock this window object adding the following code to support file
Cypress.on('window:before:load', (win) => {
console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaa', win)
win.Aurora = 'haushuhuashuas'
})
Cypress.on('window:load', (win) => {
console.log('bbbbbbbbbbbbbbbbbbbbbbbbbbbb', win)
console.log(win.Aurora)
})
Unfortunately when the test runs, 'window:before:load' never runs and does not execute console.log and does not append the value to the window. Is there another way to intercept the window and append data to window so that my component should use it when the test runs?