javascript - Unit testing $modal with Jasmine -


I have an angle app with controller that during a function there is a corner-strap modal window Displays Pu It works correctly in Chrome, but I am on the loss of the work of a valid unit test.

App Module and Foo Controller:

  var App = Angular Module ("app", ["mgcrea.ngStrap"]); App.controller ("FooController", function ($ radius, $ model) {var fooModal = $ modal ({title: 'Foo', content: 'bar', show: wrong, html: true, backdrop: 'static' placement : 'Center'}); angular.product ($ area, {makeItFoo: function ()} {fooModal.show ();}});}); Description of the Administrator:   
  ('FU controller', function () {different scope, controller, model ; First module ('app', function ($ rendered) {// Study Out $ modal service $. Value ('$ modal', function) {return {hide}: function () {}, show: function () {}};});})); First (inject (function ($ Rootscope, $ controller, $ injector) {// set a new area and controller for test scope = $ rootScope. $ New (); Controller = $ controller ('FooController', $ $ scope : Scope}); modal = $ injector.get ('$ modal');})); ('Model should be shown', function () {var modalSpy = spyOn (model (), 'show'); scope.makeItFoo (); Hopefully (modalSpy) .toHaveBeenCalled ();});});  

I hope to display my call on makeItFoo () , but test with Jasmin error Fails to be called . I tried to set the model property for show to true and did not separate show from calling, And I have tried other forms $ Modal service stubbing and direct injection in the controller, but it ends with the same error.

I am using AngularJS 1.2.14, Glass Strap 2.0.0, and Jasmin 1.3. 1.

Instead of show and hide mode, with $ modal Make a counterfeit object and set your expectations on them.

  Description ('FooController', function () {var scope, before controller (each module ('app')); (injection ($ root scope, $ controller) {// Set a new radius and provide modal as the dependency for controller = $ rootScope. $ New (); / / controller = $ controller ('FooController', {$ scope: scope, / controller) ) / Spy object modal = jasmine.createSpyObj ('show', 'hide']) $ Modal: modal});}); ('Must show model', function () {scope.makeItFoo (); Hope (modal.show) .toHaveBeenCalled ();});});  

Comments