title: Unit testing $modal with Jasmine
body: <p>I have an Angular app with a controller which displays an <code>Angular-Strap</code> modal window during a function call. It functions correctly in Chrome, but I am at a loss getting a valid unit test working.</p>
  <p><strong>App module and the FooController:</strong></p>
  <pre><code>var app = angular.module(&quot;app&quot;, [&quot;mgcrea.ngStrap&quot;]);
  
  app.controller(&quot;FooController&quot;, function($scope, $modal) {
      var fooModal = $modal({
          title: 'Foo',
          content:'Bar',
          show: false,
          html: true,
          backdrop: 'static',
          placement: 'center'});
      
      angular.extend($scope, {
          makeItFoo: function() {
              fooModal.show();
          }
      });
  });
  </code></pre>
  <p><strong>Controller spec:</strong></p>
  <pre><code>describe('FooController', function () {
      var scope, controller, modal;
  
      beforeEach(module('app', function ($provide) {
          // Stub out $modal service
          $provide.value('$modal', function () {
              return {
                  hide: function () { },
                  show: function () { }
              };
          });
      }));
  
      beforeEach(inject(function ($rootScope, $controller, $injector) {
          //set up a new scope and the controller for the test
          scope = $rootScope.$new();
          controller = $controller('FooController', {$scope: scope});
          modal = $injector.get('$modal');
      }));
  
      it('should show the modal', function () {
          var modalSpy = spyOn(modal(), 'show');
          
          scope.makeItFoo();
          
          expect(modalSpy).toHaveBeenCalled();
      });
  });
  </code></pre>
  <p><a href="http://jsfiddle.net/dimmreaper/jwom7ns2/" rel="noreferrer">Here's a fiddle as well.</a></p>
  <p>I expect my call to <code>makeItFoo()</code> to display the modal, but Jasmine fails the test with the error <code>Expected spy show to have been called</code>. I've also tried setting the <code>show</code> property of the modal to <code>true</code> and not calling <code>show()</code> separately, and I've tried other variants of stubbing the $modal service and injecting it directly into the controller, but it ends up with the same error.</p>
  <p>I'm using AngularJS 1.2.14, Angular-Strap 2.0.0, and Jasmine 1.3.1.</p>