How to set Tealium-Angular configuration in a karma test

293 Views Asked by At

There is a tagging library here: 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:

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:

"account or profile value not set. Please configure Tealium first"

How can I set these config values in my karma test?

2

There are 2 best solutions below

0
On BEST ANSWER

The solution was (my colleague Andrea Fűrész fixed it actually):

She created a js file with the following content:

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. Then it worked.

4
On

In the test you can provide your own implementation for TealiumHelper module like

describe('controllertest', function () {

    beforeEach(module('appname'))

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

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