为什么 $injector 在我的单元测试中没有找到 $state? [英] Why isn't $injector finding $state in my unit test?

查看:24
本文介绍了为什么 $injector 在我的单元测试中没有找到 $state?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的模块和单元测试设置.当我尝试设置 $state 时,$injector.get("$state") 抛出总是很有趣的 Unknown provider: $stateProvider <- $state 错误,我不明白为什么.

The following is my module and unit test set-up. When I try to set $state, $injector.get("$state") throws the always fun Unknown provider: $stateProvider <- $state error and I don't understand why.

angular.module("my-module", [
        //Third Party
        "ui.bootstrap",
        "ui.router",
        "toaster",
        "angular-loading-bar",
        "ngAnimate",
        "ngSanitize",
        "ApplicationInsightsModule",
        "pascalprecht.translate"
]);

describe("something descriptive and helpful", (): void => {
    // a bunch of other service variables....
    var $state: any;

    // I've tried with and without this line
    beforeEach(() => angular.module("ui.router")); 

    beforeEach(() => {

        angular.module("my-module");

        inject(($injector: ng.auto.IInjectorService): void => {
            // a bunch of other service variable assignments
            $state = $injector.get("$state");
        });
});

推荐答案

需要致电

angular.mock.module("my-module")

加载模块.

这篇关于为什么 $injector 在我的单元测试中没有找到 $state?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆