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

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

执行下面的单元测试给出 "Error: [$injector:unpr] Unknown provider: $stateProvider <- $state"。我在 karma 文件中附加了 angular-ui-router.min.js。

 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");
    });
  });
});

您还没有加载任何模块,所以根本没有可用的服务。在你的 beforeEach 之前添加这个:

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