bahmutov / cypress-svelte-unit-test

Unit testing Svelte components in Cypress E2E test runner
162 stars 21 forks source link

document and window event listeners don't fire #60

Closed JohnnyFun closed 4 years ago

JohnnyFun commented 4 years ago

Is this a bug report or a feature request?

bug report

If this is a bug report, please provide as much info as possible

Test.svelte:

<div>Doc click: {docClicks}</div>
<div>Win click: {winClicks}</div>

<script>
  export let docClicks = 0
  export let winClicks = 0
  document.addEventListener('click', e => docClicks++)
  window.addEventListener('click', e => winClicks++)
</script>

Cypress spec:

import Test from 'Test'
import mount from 'cypress-svelte-unit-test'

describe('Test', () => {
  it('works', () => {
    mount(Test).then(() => {
      cy.viewport(600, 600)
      cy.get('body').click() // also doesn't work to manually click from within the cypress test runner UI
      // Cypress.component.$set({ docClicks: 1, winClicks: 1 }) // works, fwiw
      cy.get('div').contains('Doc click: 1')
      cy.get('div').contains('Win click: 1')
    })
  })
})
bahmutov commented 4 years ago

:tada: This issue has been resolved in version 2.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: