Unit testing

ashishgujja
Rookie Contributor
ashishgujja

Has anyone incorporated or know how to incorporate unit testing with or without using a framework (such as Mocha.js, Jasmine, QUnit etc.) for utag.js and/or extensions/tags created in Tealium? 

2 REPLIES 2

Unit testing

Tealium Employee

A few tips for testing tags:

  1. Delay test start until third party libraries and api calls have loaded.
  2. URLs from successful script, iframe and pixel requests can be viewed in chrome browsers using getNetworkResources(). This will include data passed via query string parameters that can be verified against your data layer.
  3. To view the log from utag.js, set the utagdb cookie to true before page load document.cookie = “utagdb=true”;. utag.db_log will then contain information whether or not a tag or extension fired. (e.g. 1234: Tag not fired: Required attribute “account_id” not populated)

An example of using Mocha.js and Chai.js to test whether your tag library was loaded:

it("Should load library.js", function() {
const urls = getNetworkResources().filter(url => {return url.includes("library.js")});
expect(urls).to.have.lengthOf(1);
});

 

Unit testing

Community Manager
Community Manager

@ashishgujja Such an interesting topic, we wrote a blog post about it! Enjoy!

Unit Testing Your Tealium Implementation with Mocha and Chai

Remember to "Accept as Solution" when your question has been answered and to give kudos to helpful replies.