Skip to content

Commit 06e7e3e

Browse files
committed
Merge branch 'master' into zeeshan/datafile-auth
2 parents 01931df + cc6a6b6 commit 06e7e3e

File tree

5 files changed

+65
-78
lines changed

5 files changed

+65
-78
lines changed

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ import eventProcessorConfigValidator from './utils/event_processor_config_valida
2828
var LocalStoragePendingEventsDispatcher = eventProcessor.LocalStoragePendingEventsDispatcher;
2929

3030
describe('javascript-sdk', function() {
31+
var clock;
32+
beforeEach(function() {
33+
sinon.stub(optimizelyFactory.eventDispatcher, 'dispatchEvent');
34+
clock = sinon.useFakeTimers(new Date());
35+
});
36+
37+
afterEach(function() {
38+
optimizelyFactory.eventDispatcher.dispatchEvent.restore();
39+
clock.restore();
40+
});
41+
3142
describe('APIs', function() {
3243
it('should expose logger, errorHandler, eventDispatcher and enums', function() {
3344
assert.isDefined(optimizelyFactory.logging);
@@ -166,19 +177,6 @@ describe('javascript-sdk', function() {
166177
assert.equal('react-sdk', optlyInstance.clientEngine);
167178
});
168179

169-
it('should allow passing of "react-sdk" as the clientEngine', function() {
170-
var optlyInstance = optimizelyFactory.createInstance({
171-
clientEngine: 'react-sdk',
172-
datafile: {},
173-
errorHandler: fakeErrorHandler,
174-
eventDispatcher: fakeEventDispatcher,
175-
logger: silentLogger,
176-
});
177-
// Invalid datafile causes onReady Promise rejection - catch this error
178-
optlyInstance.onReady().catch(function() {});
179-
assert.equal('react-sdk', optlyInstance.clientEngine);
180-
});
181-
182180
it('should activate with provided event dispatcher', function() {
183181
var optlyInstance = optimizelyFactory.createInstance({
184182
datafile: testData.getTestProjectConfig(),
@@ -393,7 +391,7 @@ describe('javascript-sdk', function() {
393391
describe('event processor configuration', function() {
394392
var eventProcessorSpy;
395393
beforeEach(function() {
396-
eventProcessorSpy = sinon.stub(eventProcessor, 'LogTierV1EventProcessor').callThrough();
394+
eventProcessorSpy = sinon.spy(eventProcessor, 'LogTierV1EventProcessor');
397395
});
398396

399397
afterEach(function() {

packages/optimizely-sdk/lib/index.react_native.tests.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,20 @@ import testData from './tests/test_data';
2323
import packageJSON from '../package.json';
2424
import optimizelyFactory from './index.react_native';
2525
import configValidator from './utils/config_validator';
26-
import defaultEventDispatcher from './plugins/event_dispatcher/index.browser';
2726
import eventProcessorConfigValidator from './utils/event_processor_config_validator';
2827

2928
describe('javascript-sdk/react-native', function() {
29+
var clock;
30+
beforeEach(function() {
31+
sinon.stub(optimizelyFactory.eventDispatcher, 'dispatchEvent');
32+
clock = sinon.useFakeTimers(new Date());
33+
});
34+
35+
afterEach(function() {
36+
optimizelyFactory.eventDispatcher.dispatchEvent.restore();
37+
clock.restore();
38+
});
39+
3040
describe('APIs', function() {
3141
it('should expose logger, errorHandler, eventDispatcher and enums', function() {
3242
assert.isDefined(optimizelyFactory.logging);
@@ -120,26 +130,15 @@ describe('javascript-sdk/react-native', function() {
120130
});
121131

122132
describe('when no event dispatcher passed to createInstance', function() {
123-
beforeEach(function() {
124-
sinon.stub(defaultEventDispatcher, 'dispatchEvent', function(evt, cb) {
125-
cb();
126-
});
127-
});
128-
129-
afterEach(function() {
130-
defaultEventDispatcher.dispatchEvent.restore();
131-
});
132-
133133
it('uses the default event dispatcher', function() {
134134
var optlyInstance = optimizelyFactory.createInstance({
135135
datafile: testData.getTestProjectConfig(),
136136
errorHandler: fakeErrorHandler,
137137
logger: silentLogger,
138138
});
139139
optlyInstance.activate('testExperiment', 'testUser');
140-
return optlyInstance.close().then(function() {
141-
sinon.assert.calledOnce(defaultEventDispatcher.dispatchEvent);
142-
});
140+
clock.tick(30001)
141+
sinon.assert.calledOnce(optimizelyFactory.eventDispatcher.dispatchEvent);
143142
});
144143
});
145144

@@ -185,7 +184,7 @@ describe('javascript-sdk/react-native', function() {
185184
describe('event processor configuration', function() {
186185
var eventProcessorSpy;
187186
beforeEach(function() {
188-
eventProcessorSpy = sinon.stub(eventProcessor, 'LogTierV1EventProcessor').callThrough();
187+
eventProcessorSpy = sinon.spy(eventProcessor, 'LogTierV1EventProcessor');
189188
});
190189

191190
afterEach(function() {

0 commit comments

Comments
 (0)