加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 使用Angular Mocks测试Angular:Provider’$$sanit

发布时间:2020-12-17 18:09:14 所属栏目:安全 来源:网络整理
导读:我正在使用Angular Mocks测试我的应用程序,当它尝试创建一些模块时,我遇到了这个问题. describe('navRegisterOverrideSpec',function () { var navigationServiceProvider; beforeEach(module('wrapper')); describe('remove un needed navs',function () {
我正在使用Angular Mocks测试我的应用程序,当它尝试创建一些模块时,我遇到了这个问题.

describe('navRegisterOverrideSpec',function () {
  var navigationServiceProvider;

  beforeEach(module('wrapper'));

  describe('remove un needed navs',function () {
    var navigationService;

    beforeEach(
      inject(function ($injector) {
        navigationService = $injector.get('navigationService');
      }));

    it('Should not have admin menu',function () {
      var filtered = _.filter(navigationService.items,function (item) {
        return item.id == 'admin_menu';
      });

      expect(filtered.length).toEqual(0);
    });
  });
});

以下是我得到的错误.

Error: [$injector:modulerr] Failed to instantiate module ng due to:
Error: [$injector:pget] Provider '$$sanitizeUri' must define $get factory method.
http://errors.angularjs.org/1.5.5/$injector/pget?p0=%24%24sanitizeUri
    at provider (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4497)
    at D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:366
    at forEach (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:336)
    at D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4484
    at ngModule (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:2530)
    at invoke (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4665)
    at runInvokeQueue (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4558)
    at D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4567
    at forEach (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:322)
    at loadModules (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4590)
    at createInjector (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4470)
    at workFn (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular-mocks/angular-mocks.js:2464)
http://errors.angularjs.org/1.5.5/$injector/modulerr?p0=ng&p1=Error%3A%20%5B%24injector%3Apget%5D%20Provider%20'%

我找不到任何答案.任何帮助,将不胜感激.

解决方法

我遇到了同样的问题,并偶然发现 this github问题,然后引导我进入 linked github问题.我不知道你是否使用业力作为你的无头网络浏览器的测试运行器和幻像,但更新我的业力 – 幻影启动器到^ 1.0.0最终解决了我的问题.

问题的原因(对于那些不想通过我上面提到的链接的人)是PhantomJS没有得到Angular的正式支持,反过来旧版本的karma-phantomjs-launcher使用的是旧的Web引擎处理new / bind的方式与Angular的用法不同.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读