stephan-v's avatar

How to unit test modals?

I just started unit testing with php and so far everything is going alright. But now I am running into problems because I have bootstrap modals set up to display when you click a register link in the navigation.

Since phpunit runs it can't possible interact with these modals since they are launched with javascript upon click of a register link. Preferable I would like to test if everything goes ok when a user:

  1. Clicks a register link launching the modal
  2. Fills out the forms inputs
  3. Clicks the register button to send the data
  4. Sees a confirmed sweet alert popup.

This is probably extremely hard to do as a unit test and so far my alternative approach has been to just set up some routes with forms that are not modals so phpunit can visit a page.

Does anybody have any advice on how to go about testing this or is it simply impossible even with a combinations of phpunit and javascript unit testing? I am pretty experience with unit testing so I might be going in the wrong direction here.

0 likes
1 reply
pmall's avatar

The farthest you can go without using something like selenium is to perform the post request with parameters (with call, without filling the form) and see if everything goes well.

Please or to participate in this conversation.