如何在Jasmine中模拟外部枚举设置

时间:2018-10-15 21:36:31

标签: angularjs enums jasmine

我正在用Jasmine测试AngularJS服务。该服务使用另一个模块中的枚举作为参数来调用另一个服务中的函数。

public getSavedColumns = (): ng.IPromise<GridColumn[]> => {
    return this.productSettingsService.readProjectSetting(
        psfc.ApplicationId.Calculator, this.getColumnStorageProperty())
        .then(response => { /**/ });
};

psfc.ApplicationId是另一个模块中的枚举:

export enum ApplicationId {
    Calculator = 2636
}

茉莉花测试失败,并显示以下错误:

  

TypeError'undefined'不是一个对象(正在评估'psfc.ApplicationId.Calculator')

我以为我可以在测试中嘲笑枚举,但不会改变结果。

beforeEach(() => {
    angular.mock.module('pw_psfc',
        $provide => {
            $provide.constant('psfc.ApplicationId.Calculator', 0);
        });
});

1 个答案:

答案 0 :(得分:0)

我能够通过在karma配置中包含导出的枚举文件来解决我的问题。五个月是一个非常缓慢的学习曲线,但我要到达那里! =〜)

相关问题