Offline event

<script>
  window.addEventListener('offline', () => {
    alert('Now offline!')
  })
  window.addEventListener('online', () => {
    alert('Back online!')
  })
</script>
cy.window().then((win) => {
  cy.stub(win, 'alert').as('alert')
})
cy.window().trigger('offline')
cy.get('@alert')
  .should('have.been.calledOnceWith', 'Now offline!')
  .invoke('resetHistory')

After we reset the stub, we can check if the application calls alert when the browser signals the network is available again.

cy.window().trigger('online')
cy.get('@alert').should(
  'have.been.calledOnceWith',
  'Back online!',
)