0

I'm trying to write a Unit Test that checks if a modal window (sweetalert) is present in the headless browser. To test if it's present, I can use this jQuery accessor

$('*').hasClass('sweet-overlay')

From testing sweetalert in Chrome, I do not believe this window is added to the DOM asynchronously. Also, according to the documentation, there isn't a load event.

However, in the test suite, the unit test finishes before the sweetalert window is added to the DOM. I can verify this by logging to the console.

So the question is, how do I test this? Is there a way to add a watch on the phanton.js DOM and listen for changes?

Note this is in an Angular application, so if there is a way to do this with Angular, that would great.

EDIT - I am not using Selenium. the title clearly states I'm using Jasmine.

user714157
  • 399
  • 2
  • 4
  • 18

1 Answers1

0

Hope this helps anyone else running into an issue with buttons clicks and Jasmine unit tests -

Turns out there is a timing issue with button clicks and assertions in Jasmine. The unit test would execute before the button click event.

In the code I was testing, I had the sweet alert window launching in a button click handler.

I refactored some of that code so the button click calls another method, showSweetAlert().

In my unit test, I can call showSweetAlert() and everything works like a charm.

user714157
  • 399
  • 2
  • 4
  • 18