Expand my Community achievements bar.

Extension Developers: tip for unit testing with turbine

Avatar

Community Advisor

1/26/21

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!