lundi 21 janvier 2019

testing if preventDefault was called when using stopPropagation() in the function

I have an onclick event that has event.preventDefault() as part of the function. I've added event.stopPropagation() to the function to fix a bug (where an event was firing twice, the solution works), and it's now breaking other existing tests that are testing if the preventDefault was called.

I've tried replacing the $(document) with the actual button but it's still failing.

The test code that is now failing:

  it 'is blocked when initially clicking the form button', ->
    isDefaultActionPrevented = false
    $(document).on('click', '.button-in-question', (e) ->
      isDefaultActionPrevented = e.isDefaultPrevented()
    )

     buttonOnForm.click()
     expect(isDefaultActionPrevented).toEqual(true)

This test fails. If I remove stopPropagation then it passes

Aucun commentaire:

Enregistrer un commentaire