Cypress.Commands.add('nextMount', (component, options) => {
const router = {
route: '/',
pathname: '/',
query: {},
asPath: '/',
basePath: '',
back: cy.stub().as('router:back'),
forward: cy.stub().as('router:forward'),
push: cy.stub().as('router:push'),
reload: cy.stub().as('router:reload'),
replace: cy.stub().as('router:replace'),
isReady: true,
...(options?.router || {}),
}
const headManager = {
updateHead: cy.stub().as('head:updateHead'),
mountedInstances: new Set(),
updateScripts: cy.stub().as('head:updateScripts'),
scripts: new Set(),
getIsSsr: () => false,
appDir: false,
nonce: '_',
...(options?.head || {})
}
const FallbackImage =
cy.intercept('_next/image*', {
statusCode: 200,
headers: { 'Content-Type': 'image/png' },
body: FallbackImage.buffer,
})
return mount(
<HeadManagerContext.Provider value={headManager}>
<RouterContext.Provider value={router}>
{component}
</RouterContext.Provider>
</HeadManagerContext.Provider>,
options
)
})