Skip to content

Commit 2232d1a

Browse files
authored
fix: intialize with custom user provider (#73)
1 parent 7b02565 commit 2232d1a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/experiment-browser/src/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ const initialize = (
2828
const connector = AnalyticsConnector.getInstance(instanceName);
2929
if (!instances[instanceKey]) {
3030
config = {
31+
...config,
3132
userProvider: new DefaultUserProvider(
3233
connector.applicationContextProvider,
3334
config?.userProvider,
3435
),
35-
...config,
3636
};
3737
instances[instanceKey] = new ExperimentClient(apiKey, config);
3838
}

packages/experiment-browser/test/factory.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,15 @@ test('Experiment.initialize, same instance name, different api key, different ob
3030
const client2 = Experiment.initialize(OTHER_KEY);
3131
expect(client2).not.toBe(client1);
3232
});
33+
34+
test('Experiment.initialize, custom user provider wrapped correctly', async () => {
35+
const customUserProvider = {
36+
getUser: () => {
37+
return { user_id: 'user_id' };
38+
},
39+
};
40+
const client1 = Experiment.initialize(API_KEY, {
41+
userProvider: customUserProvider,
42+
});
43+
expect(client1.getUserProvider()).not.toStrictEqual(customUserProvider);
44+
});

0 commit comments

Comments
 (0)