Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 9d249a2

Browse files
test: tests for automatically created logger instances (optimizely#197)
1 parent 09075ed commit 9d249a2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/optimizely-sdk/lib/index.browser.umdtests.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,46 @@ describe('javascript-sdk', function() {
230230
var variation = optlyInstance.getVariation('testExperimentNotRunning', 'testUser');
231231
assert.strictEqual(variation, null);
232232
});
233+
234+
describe('automatically created logger instances', function() {
235+
beforeEach(function() {
236+
sinon.spy(console, 'log')
237+
});
238+
239+
afterEach(function() {
240+
console.log.restore();
241+
});
242+
243+
it('should instantiate the logger with a custom logLevel when provided', function() {
244+
// checking that INFO logs do not log for a logLevel of ERROR
245+
var optlyInstance = window.optimizelySdk.createInstance({
246+
datafile: testData.getTestProjectConfig(),
247+
logLevel: enums.LOG_LEVEL.ERROR,
248+
skipJSONValidation: true
249+
});
250+
assert.strictEqual(console.log.getCalls().length, 0)
251+
252+
// checking that ERROR logs do log for a logLevel of ERROR
253+
var optlyInstanceInvalid = window.optimizelySdk.createInstance({
254+
datafile: {},
255+
logLevel: enums.LOG_LEVEL.ERROR
256+
});
257+
optlyInstance.activate('testExperiment', 'testUser')
258+
assert.strictEqual(console.error.getCalls().length, 1)
259+
});
260+
261+
it('should default to INFO when no logLevel is provided', function() {
262+
// checking that INFO logs log for an unspecified logLevel
263+
var optlyInstance = window.optimizelySdk.createInstance({
264+
datafile: testData.getTestProjectConfig(),
265+
skipJSONValidation: true
266+
});
267+
assert.strictEqual(console.log.getCalls().length, 1)
268+
call = console.log.getCalls()[0]
269+
assert.strictEqual(call.args.length, 1)
270+
assert(call.args[0].indexOf('OPTIMIZELY: Skipping JSON schema validation.') > -1)
271+
});
272+
});
233273
});
234274
});
235275
});

0 commit comments

Comments
 (0)