Error: [$injector:unpr] Unknown provider: $stateProvider <- $state

寵の児 提交于 2019-12-06 18:09:52

问题


Executing below unit test gives "Error: [$injector:unpr] Unknown provider: $stateProvider <- $state". I have attached the angular-ui-router.min.js in karma file.

 describe("Unit tests", function() {

  var $rootScope, $injector, $state;
  console.log("hello");

  beforeEach(inject(function(_$rootScope_, _$state_, _$injector_, $templateCache) {
    console.log("hello1");
    $rootScope = _$rootScope_;
    $injector = _$injector_;
    $state = _$state_;
  }));

  describe("states", function() {
    it("verify state configuration", function() {
        var config = $state.get("DRaaS");
        console.log(config, "cc");
    });
  });
});

回答1:


You haven't loaded any module, so no service at all is available. Add this before your beforeEach:

beforeEach(module('ui.router'));


来源:https://stackoverflow.com/questions/28737371/error-injectorunpr-unknown-provider-stateprovider-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!