title: Unit test $mdDialog angular material
body: <p>I called one $mdDialog inside a function. I want to unit-test $mdDialog ok and cancel cases.</p>
  
  <p>The below is my controller code (<strong>app.controller.js</strong>).  </p>
  
  <pre><code> (function () {
      'use strict';
  
      app.controller('AppCtrl', AppCtrl);
  
      AppCtrl.$inject = ['$scope', '$mdDialog'];
  
      function AppCtrl($scope, $mdDialog) {
  
          $scope.saveEntry = function (ev) {
              var confirm = $mdDialog.prompt()
                  .title('Save Entry')
                  .textContent('If you want, you can add a description to explain what you changed.')
                  .placeholder('Version Description')
                  .ariaLabel('Version Description')
                  .initialValue('')
                  .targetEvent(ev)
                  .ok('Save')
                  .cancel('Cancel');
  
              $mdDialog.show(confirm).then(function (result) {
                  $scope.status = true;
              }, function () {
                  $scope.status = false;
              });
          };
      }
  
  })();
  </code></pre>
  
  <p>The following is the spec code (<strong>app.controller.spec.js</strong>) :</p>
  
  <pre><code>describe('Unit test AppController: mdDialog', function () {
      var $controller, $mdDialog;
      beforeEach(function () {
          module('App');
          inject(function (_$controller_, _$mdDialog_) {
              $controller = _$controller_;
              $mdDialog = _$mdDialog_;
          });
      });
  
      it(': Opened', function () {
          var $scope = {};
          var controller = $controller('AppCtrl', { $scope: $scope });
  
          var $mdDialogOpened = false;
          $mdDialog.show = jasmine.createSpy().and.callFake(function () {
              $mdDialogOpened = true;
          });
  
          $scope.saveEntry();
          $scope.$digest();
  
          expect($mdDialog.show).toHaveBeenCalled;
          expect($mdDialogOpened).toBe.true;
      });
  });
  </code></pre>
  
  <p>when I running the above code I'm getting the following error: 
  <strong>TypeError: Cannot read property 'then' of undefined</strong></p>
  
  <p>I referred this GitHub issue <a href="https://github.com/angular/material/issues/1482" rel="nofollow noreferrer">https://github.com/angular/material/issues/1482</a>. But I'm not getting solution for my problem</p>
  
  <p>Thanks in advance</p>