Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions packages/optimizely-sdk/lib/index.browser.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ import eventProcessorConfigValidator from './utils/event_processor_config_valida
var LocalStoragePendingEventsDispatcher = eventProcessor.LocalStoragePendingEventsDispatcher;

describe('javascript-sdk', function() {
var clock;
beforeEach(function() {
sinon.stub(optimizelyFactory.eventDispatcher, 'dispatchEvent');
clock = sinon.useFakeTimers(new Date());
});

afterEach(function() {
optimizelyFactory.eventDispatcher.dispatchEvent.restore();
clock.restore();
});

describe('APIs', function() {
it('should expose logger, errorHandler, eventDispatcher and enums', function() {
assert.isDefined(optimizelyFactory.logging);
Expand Down Expand Up @@ -166,19 +177,6 @@ describe('javascript-sdk', function() {
assert.equal('react-sdk', optlyInstance.clientEngine);
});

it('should allow passing of "react-sdk" as the clientEngine', function() {
var optlyInstance = optimizelyFactory.createInstance({
clientEngine: 'react-sdk',
datafile: {},
errorHandler: fakeErrorHandler,
eventDispatcher: fakeEventDispatcher,
logger: silentLogger,
});
// Invalid datafile causes onReady Promise rejection - catch this error
optlyInstance.onReady().catch(function() {});
assert.equal('react-sdk', optlyInstance.clientEngine);
});

Comment on lines -169 to -181
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted this because it's identical to the test above.

it('should activate with provided event dispatcher', function() {
var optlyInstance = optimizelyFactory.createInstance({
datafile: testData.getTestProjectConfig(),
Expand Down Expand Up @@ -393,7 +391,7 @@ describe('javascript-sdk', function() {
describe('event processor configuration', function() {
var eventProcessorSpy;
beforeEach(function() {
eventProcessorSpy = sinon.stub(eventProcessor, 'LogTierV1EventProcessor').callThrough();
eventProcessorSpy = sinon.spy(eventProcessor, 'LogTierV1EventProcessor');
});

afterEach(function() {
Expand Down
29 changes: 14 additions & 15 deletions packages/optimizely-sdk/lib/index.react_native.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ import testData from './tests/test_data';
import packageJSON from '../package.json';
import optimizelyFactory from './index.react_native';
import configValidator from './utils/config_validator';
import defaultEventDispatcher from './plugins/event_dispatcher/index.browser';
import eventProcessorConfigValidator from './utils/event_processor_config_validator';

describe('javascript-sdk/react-native', function() {
var clock;
beforeEach(function() {
sinon.stub(optimizelyFactory.eventDispatcher, 'dispatchEvent');
clock = sinon.useFakeTimers(new Date());
});

afterEach(function() {
optimizelyFactory.eventDispatcher.dispatchEvent.restore();
clock.restore();
});

describe('APIs', function() {
it('should expose logger, errorHandler, eventDispatcher and enums', function() {
assert.isDefined(optimizelyFactory.logging);
Expand Down Expand Up @@ -120,26 +130,15 @@ describe('javascript-sdk/react-native', function() {
});

describe('when no event dispatcher passed to createInstance', function() {
beforeEach(function() {
sinon.stub(defaultEventDispatcher, 'dispatchEvent', function(evt, cb) {
cb();
});
});

afterEach(function() {
defaultEventDispatcher.dispatchEvent.restore();
});

it('uses the default event dispatcher', function() {
var optlyInstance = optimizelyFactory.createInstance({
datafile: testData.getTestProjectConfig(),
errorHandler: fakeErrorHandler,
logger: silentLogger,
});
optlyInstance.activate('testExperiment', 'testUser');
return optlyInstance.close().then(function() {
sinon.assert.calledOnce(defaultEventDispatcher.dispatchEvent);
});
clock.tick(30001)
sinon.assert.calledOnce(optimizelyFactory.eventDispatcher.dispatchEvent);
});
});

Expand Down Expand Up @@ -185,7 +184,7 @@ describe('javascript-sdk/react-native', function() {
describe('event processor configuration', function() {
var eventProcessorSpy;
beforeEach(function() {
eventProcessorSpy = sinon.stub(eventProcessor, 'LogTierV1EventProcessor').callThrough();
eventProcessorSpy = sinon.spy(eventProcessor, 'LogTierV1EventProcessor');
});

afterEach(function() {
Expand Down
Loading