angularJS fullstack :: assertionError:预期open已被参数匹配调用

时间:2017-01-25 11:50:35

标签: angularjs angular-fullstack karma-mocha

在我的控制器中有一个功能......

function showDesktopPreview() {
      var self = this;
      this.$uibModal.open({
        templateUrl: 'app/templates/modals/desktopPreview/template.desktopPreview.html',
        controller: 'TemplateDesktopPreviewModalController',
        controllerAs: 'vm',
        size: 'xl',
        resolve: {
          previewUrl: function previewUrl() {
            return self.getFrameUrl();
          }
        }
      });
    }
  }

现在我写下Karma测试脚本如下....

describe('When calling the showDesktopPreview function', () => {
      let modalOptions;
      let previewUrl;
      beforeEach(() => {
        TemplatesCreateController = createController();
        //previewUrl = TemplatesCreateController.getFrameUrl();
        modalOptions = {
          templateUrl: 'app/templates/modals/desktopPreview/template.desktopPreview.html',
          controller: 'TemplateDesktopPreviewModalController',
          controllerAs: 'vm',
          size: 'x1',
          resolve: {
            previewUrl: (value) => {
              return value() === TemplatesCreateController.previewUrl();
            }
          }
        };
        console.log(modalOptions.resolve.previewUrl);
        TemplatesCreateController.showDesktopPreview();
      });
      it('should instantiate the $uibModal service ', () => {
   expect(TemplatesCreateController.$uibModal).to.not.be.an('undefined');
      });
      it('should call $uibModal.open with correct params', () => {
        scope.$apply();
        expect(TemplatesCreateController.$uibModal.open).to.have
        .been.called
        .and.be.calledWithMatch({modalOptions});
      });
  });

这是错误的

断言错误:预期已通过匹配

的参数调用open

请帮我解决此问题。

0 个答案:

没有答案