I am new to unit testing as well as in angularjs.
When I unit test my modal if they are showing or not, an error was returned:
> TypeError: undefined is not a constructor (evaluating
> '$('#modalId').modal('show')')
How can I unit test my modals ?
It depends on what testing framework you are using. In case of
jasmineyou can spy on modal. Lets say you have this controller:Then the test looks like this:
You need to return a
mockof what$modal.opennormally returns, not a mock of$modal, which doesn’t include anopenfunction is laid out infakeModalmock. The fake modal must have aresultobject that contains a then function to store the callbacks (to be called when the OK or Cancel buttons are clicked on). It also needs aclosefunction (simulating an OK button click on the modal) and adismissfunction (simulating a Cancel button click on the modal). The close and dismiss functions call the necessary call back functions when called.