Test for Alert Popup

2,303 views
Skip to first unread message

David

unread,
Dec 22, 2010, 4:01:35 PM12/22/10
to Jasmine
Is there a way to use jasmine to test for the popup of an alert/
confirm message. Currently my javascript funciton adds an onclick
event, to certain anchor tags with a specified class, to display a
confirm popup message. How do I use Jasmine to test that
functionality?

THanks

Rajan Agaskar

unread,
Dec 22, 2010, 4:08:15 PM12/22/10
to jasmi...@googlegroups.com
You should be able to spyOn(window, "confirm") or spyOn(window,
"alert"). Make sure your spy is set up before the alert/confirm
behavior gets invoked.

Thanks!

Rajan

> --
> You received this message because you are subscribed to the Google Groups "Jasmine" group.
> To post to this group, send email to jasmi...@googlegroups.com.
> To unsubscribe from this group, send email to jasmine-js+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.
>
>

David

unread,
Dec 22, 2010, 4:35:48 PM12/22/10
to Jasmine
Thanks for pointing me in the right direction. I just set up the spy,
but I am not sure how to mimic a click with javascript. I have tried:

anchor1 = document.getElementById("new");

a) anchor1.click();
b) anchor1.fireEvent("onclick");
c) anchor1.trigger("onclick");

these all give me errors with the Jasmine Test Runner.


On Dec 22, 1:08 pm, Rajan Agaskar <ragas...@gmail.com> wrote:
> You should be able to spyOn(window, "confirm") or spyOn(window,
> "alert"). Make sure your spy is set up before the alert/confirm
> behavior gets invoked.
>
> Thanks!
>
> Rajan
>
Reply all
Reply to author
Forward
0 new messages