简体   繁体   English

如何在业力测试中设置 Tealium-Angular 配置

[英]How to set Tealium-Angular configuration in a karma test

There is a tagging library here: https://github.com/Tealium/integration-angularjs/blob/master/tealium_angular.js .这里有一个标记库: https : //github.com/Tealium/integration-angularjs/blob/master/tealium_angular.js

We integrated it into our application.我们将其集成到我们的应用程序中。 During app initialisation we need to provide some configuration for this library.在应用程序初始化期间,我们需要为此库提供一些配置。 This is done like this:这是这样做的:

Our app.js:我们的 app.js:

angular.module('appname', [ 'TealiumHelper' ])
.config(function (tealiumProvider) {
            tealiumProvider.setConfig({
                account: 'accountxx',
                profile: 'profilexx',
                environment: 'dev'
            });
        })

There is a karma test similar to this:有一个类似于这样的业力测试:

(function () {
    'use strict';

    describe('controllertest', function () {
        beforeEach(module('appname','TealiumHelper'));
        it('bla', function () {
            //test code
        }
    }
}

When I start the test, I get the following error coming from tealium_angular.js :当我开始测试时,我收到来自tealium_angular.js的以下错误:

"account or profile value not set. Please configure Tealium first" “未设置帐户或配置文件值。请先配置Tealium”

How can I set these config values in my karma test?如何在我的业力测试中设置这些配置值?

In the test you can provide your own implementation for TealiumHelper module like在测试中,您可以为TealiumHelper模块提供自己的实现,例如

describe('controllertest', function () {

    beforeEach(module('appname'))

    angular.module('TealiumHelper', []).provider('tealium', {
        $get: function () {},
        setConfig: function () {}
    });

    /*** test starts here ***/
})

The solution was (my colleague Andrea Fűrész fixed it actually):解决方案是(我的同事 Andrea Fűrész 实际上修复了它):

She created a js file with the following content:她创建了一个 js 文件,内容如下:

function TealiumConfig() {
    'use strict';

    module('TealiumHelper', function (tealiumProvider) {
        tealiumProvider.setConfig({
            account: 'foooooo',
            profile: 'baaaar',
            environment: 'dev'
        })
    });
}

Then in karma config it was added into the "files" configuration.然后在 karma 配置中,它被添加到“文件”配置中。 Then it worked.然后它起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM