Extension Developers: tip for unit testing with turbine | Community
Skip to main content
yuhuisg
New Participant
January 27, 2021

Extension Developers: tip for unit testing with turbine

  • January 27, 2021
  • 0 replies
  • 726 views

This tip is for extension developers (most likely applicable for web extensions only, since I haven't tried this with mobile extensions).

TL;DR create a "global.turbine" variable to mock the turbine free variable, before running your unit tests.

I use jasmine (https://jasmine.github.io/index.html) for testing my extension. One difficulty that I had was figuring out how to test the "turbine" free variable (https://experienceleague.adobe.com/docs/launch/using/extension-dev/turbine.html).

After numerous trials-and-errors, I finally stumbled on this solution:

describe("description of the test suite", function() { // create the turbine free variable with "logger" global.turbine = { logger: jasmine.createSpyObj('', ['debug', 'info', 'warn', 'alert', 'error']), }; // rest of test suite it("description of unit test that logs to the logger", function() { // run the test expect(global.turbine.logger.info).toHaveBeenCalled(); }); });

Hope this works for you too!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.