Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – Jasmine spyon方法返回undefined大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_801_0@
@H_801_0@
我在SpyOn方法上得到一个未定义的错误

这就是我想出的

'use Strict';
describe('WebApp: AccountController',function() {
  return beforeEach(function() {
    module('webApp');
    module('tpls');
    return inject(function($injector) {
      this.q = $injector.get('$q');
      thiS.Usermock = {
        id: 1,email: 'pidsafs@gmail.com',name: 'Adones Pitogo'
      };
      this.modalmock = {
        open: (function(_this) {
          return function(tpl,ctrl) {
            _this.def = _this.q.defer();
            _this.def.resolve(true);
            return {
              result: _this.def.promise
            };
          };
        })(this)
      };
      this.teammock = {
        id: 1
      };
      this.repomock = {
        id: 1
      };
      this.httpBACkend = $injector.get('$httpBACkend');
      this.httpBACkend.whenGET('/api/v1/session').respond({
        status: 'ok',user: thiS.Usermock
      });
      this.httpBACkend.whenGET("/api/v1/users/" + thiS.Usermock.id + "/teams").respond({
        status: 'ok',teams: [this.teammock]
      });
      this.httpBACkend.whenGET("/api/v1/users/" + thiS.Usermock.id + "/repositories/remote").respond({
        status: 'ok',repositories: []
      });
      this.httpBACkend.whenGET("/api/v1/users/" + thiS.Usermock.id + "/repositories/followed").respond({
        status: 'ok',repositories: []
      });
      this.Invoiceservice = $injector.get('Common.Invoiceservice');
      this.Teamservice = $injector.get('Common.Teamservice');
      this.Repositoryservice = $injector.get('Common.Repositoryservice');
      thiS.Userservice = $injector.get('Common.Userservice');
      this.rootScope = $injector.get('$rootScope');
      this.scope = this.rootScope.$new();
      this.scope.user = thiS.Usermock;
      this.$controller = $injector.get('$controller');
      this.timeout = $injector.get('$timeout');
      this.compile = $injector.get('$compile');
      this.rootElement = $injector.get('$rootElement');
      this.toastermock = {
        pop: function(type,title,messagE) {
          return true;
        }
      };
      this.modalSpy = spyOn(this.modalmock,'open').andCallThrough();
      this.httpBACkend.flush();
      $('body').append('<div id="profile-pic-input"></div>');
      this.openFileWindow = function() {
        return this.timeout(function() {
          return $('#profile-pic-input').trigger('click');
        });
      };
      this.controller = this.$controller('AccountController',{
        '$scope': this.scope,'$rootScope': this.rootScope,'Common.Repositoryservice': this.Repositoryservice,'Common.Userservice': thiS.Userservice,'Common.Invoiceservice': this.Invoiceservice,'toaster': this.toastermock,'openFileWindow': this.openFileWindow,'Common.Teamservice': this.Teamservice
      });
      return this.scope.$digest();
    });
  });
});

我总是得到这个错误

TypeError: 'undefined' is not a function (evaluaTing 'spyOn(this.modalmock,'open').andCallThrough()')

如果我监视所有其他服务,也会发生这种情况

解决方法

我在使用Jasmine 2.x版时看到了这个问题.对我来说问题是我正在调用andCallThrough()这是 Jasmine 1.x syntax. 2.x syntax是and.callThrough().
@H_801_0@

大佬总结

以上是大佬教程为你收集整理的angularjs – Jasmine spyon方法返回undefined全部内容,希望文章能够帮你解决angularjs – Jasmine spyon方法返回undefined所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:angularjsjasminespyonundefined方法返回
猜你在找的Angularjs相关文章
其他相关热搜词更多
phpJavaPython程序员load如何string使用参数jquery开发安装listlinuxiosandroid工具javascriptcap