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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.