Skip to content

Commit d61281b

Browse files
authored
fix: Use default event dispatcher in React Native entry point when none provided by user (#383)
Summary: In the createInstance factory method of the React Native entry point, when no event dispatcher is provided by the caller in the options object, a value of undefined is set on the options object that is passed on to the Optimizely constructor. This results in an invalid instance that can't dispatch events. With this fix, the default event dispatcher is used when none is provided by the caller. Test plan: Added new unit test
1 parent bbdb2cc commit d61281b

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

packages/optimizely-sdk/CHANGELOG.MD

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8-
Changes that have landed but are not yet released.
8+
### Bug fixes
9+
- Fixed default event dispatcher not used in React Native entry point ([#383](https://github.com/optimizely/javascript-sdk/pull/383))
910

1011
## [3.4.0-beta] - December 18th, 2019
1112
### Bug fixes
@@ -14,7 +15,7 @@ Changes that have landed but are not yet released.
1415
### New Features
1516

1617
- Added a new API to get a project configuration static data.
17-
- Call `getOptimizelyConfig()` to get a snapshot copy of project configuration static data.
18+
- Call `getOptimizelyConfig()` to get a snapshot copy of project configuration static data.
1819
- It returns an `OptimizelyConfig` instance which includes a datafile revision number, all experiments, and feature flags mapped by their key values.
1920
- For details, refer to a documention page: https://docs.developers.optimizely.com/full-stack/docs/optimizelyconfig-javascript-node
2021

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ module.exports = {
9090
{
9191
clientEngine: enums.JAVASCRIPT_CLIENT_ENGINE,
9292
eventBatchSize: DEFAULT_EVENT_BATCH_SIZE,
93+
eventDispatcher: defaultEventDispatcher,
9394
eventFlushInterval: DEFAULT_EVENT_FLUSH_INTERVAL,
9495
},
9596
config,
9697
{
97-
eventDispatcher: config.eventDispatcher,
9898
// always get the OptimizelyLogger facade from logging
9999
logger: logger,
100100
errorHandler: logging.getErrorHandler(),

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var packageJSON = require('../package.json');
2222
var testData = require('./tests/test_data');
2323
var eventProcessor = require('@optimizely/js-sdk-event-processor');
2424
var eventProcessorConfigValidator = require('./utils/event_processor_config_validator');
25+
var defaultEventDispatcher = require('./plugins/event_dispatcher/index.browser');
2526

2627
var chai = require('chai');
2728
var assert = chai.assert;
@@ -131,6 +132,30 @@ describe('javascript-sdk/react-native', function() {
131132
assert.strictEqual(activate, 'control');
132133
});
133134

135+
describe('when no event dispatcher passed to createInstance', function() {
136+
beforeEach(function() {
137+
sinon.stub(defaultEventDispatcher, 'dispatchEvent', function(evt, cb) {
138+
cb();
139+
});
140+
})
141+
142+
afterEach(function() {
143+
defaultEventDispatcher.dispatchEvent.restore();
144+
});
145+
146+
it('uses the default event dispatcher', function() {
147+
var optlyInstance = optimizelyFactory.createInstance({
148+
datafile: testData.getTestProjectConfig(),
149+
errorHandler: fakeErrorHandler,
150+
logger: silentLogger,
151+
});
152+
optlyInstance.activate('testExperiment', 'testUser');
153+
return optlyInstance.close().then(function() {
154+
sinon.assert.calledOnce(defaultEventDispatcher.dispatchEvent);
155+
});
156+
});
157+
});
158+
134159
describe('when passing in logLevel', function() {
135160
beforeEach(function() {
136161
sinon.stub(logging, 'setLogLevel');

0 commit comments

Comments
 (0)