Skip to content

Commit 026aef0

Browse files
Add await to relevent setuser tests
1 parent 3a40344 commit 026aef0

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/client.spec.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('ReactSDKClient', () => {
143143
});
144144

145145
it('fulfills the returned promise with success: true when a user is set', async () => {
146-
instance.setUser({
146+
await instance.setUser({
147147
id: 'user12345',
148148
});
149149
const result = await instance.onReady();
@@ -164,7 +164,7 @@ describe('ReactSDKClient', () => {
164164
});
165165

166166
it('fulfills the returned promise with success: false when a user is set', async () => {
167-
instance.setUser({
167+
await instance.setUser({
168168
id: 'user12345',
169169
});
170170
const result = await instance.onReady();
@@ -178,7 +178,7 @@ describe('ReactSDKClient', () => {
178178
resolveInnerClientOnReady = res;
179179
});
180180
mockInnerClientOnReady.mockReturnValueOnce(mockReadyPromise);
181-
instance.setUser({
181+
await instance.setUser({
182182
id: 'user999',
183183
});
184184
resolveInnerClientOnReady!({ success: true });
@@ -194,7 +194,7 @@ describe('ReactSDKClient', () => {
194194
resolveInnerClientOnReady = res;
195195
});
196196
mockInnerClientOnReady.mockReturnValueOnce(mockReadyPromise);
197-
instance.setUser({
197+
await instance.setUser({
198198
id: 'user999',
199199
});
200200
resolveInnerClientOnReady!({ success: true });
@@ -204,9 +204,9 @@ describe('ReactSDKClient', () => {
204204
});
205205

206206
describe('setUser', () => {
207-
it('updates the user object with id and attributes', () => {
207+
it('updates the user object with id and attributes', async () => {
208208
const instance = createInstance(config);
209-
instance.setUser({
209+
await instance.setUser({
210210
id: 'xxfueaojfe8&86',
211211
attributes: {
212212
foo: 'bar',
@@ -256,9 +256,9 @@ describe('ReactSDKClient', () => {
256256

257257
describe('pre-set user and user overrides', () => {
258258
let instance: ReactSDKClient;
259-
beforeEach(() => {
259+
beforeEach(async () => {
260260
instance = createInstance(config);
261-
instance.setUser({
261+
await instance.setUser({
262262
id: 'user1',
263263
attributes: {
264264
foo: 'bar',
@@ -913,7 +913,7 @@ describe('ReactSDKClient', () => {
913913
});
914914

915915
describe('if Optimizely client is null', () => {
916-
it('does not return an object with variables of all types returned from the inner sdk ', () => {
916+
it('does not return an object with variables of all types returned from the inner sdk ', async () => {
917917
(mockInnerClient.getOptimizelyConfig as jest.Mock).mockReturnValue({
918918
featuresMap: {
919919
feat1: {
@@ -971,7 +971,7 @@ describe('ReactSDKClient', () => {
971971
}
972972
);
973973
const instance = createInstance(config);
974-
instance.setUser({
974+
await instance.setUser({
975975
id: 'user1123',
976976
});
977977
// @ts-ignore
@@ -981,7 +981,7 @@ describe('ReactSDKClient', () => {
981981
});
982982
});
983983

984-
it('returns an object with variables of all types returned from the inner sdk ', () => {
984+
it('returns an object with variables of all types returned from the inner sdk ', async () => {
985985
(mockInnerClient.getOptimizelyConfig as jest.Mock).mockReturnValue({
986986
featuresMap: {
987987
feat1: {
@@ -1039,7 +1039,7 @@ describe('ReactSDKClient', () => {
10391039
}
10401040
);
10411041
const instance = createInstance(config);
1042-
instance.setUser({
1042+
await instance.setUser({
10431043
id: 'user1123',
10441044
});
10451045
const result = instance.getFeatureVariables('feat1');
@@ -1057,7 +1057,7 @@ describe('ReactSDKClient', () => {
10571057

10581058
describe('getAllFeatureVariables', () => {
10591059
describe('if Optimizely client is null', () => {
1060-
it('does not return an object with variables of all types returned from the inner sdk ', () => {
1060+
it('does not return an object with variables of all types returned from the inner sdk ', async () => {
10611061
const anyClient = mockInnerClient.getAllFeatureVariables as jest.Mock;
10621062
anyClient.mockReturnValue({
10631063
bvar: true,
@@ -1071,14 +1071,14 @@ describe('ReactSDKClient', () => {
10711071
const instance = createInstance(config);
10721072
// @ts-ignore
10731073
instance._client = null;
1074-
instance.setUser({
1074+
await instance.setUser({
10751075
id: 'user1123',
10761076
});
10771077
const result = instance.getAllFeatureVariables('feat1', 'user1');
10781078
expect(result).toEqual({});
10791079
});
10801080

1081-
it('cannot use pre-set and override user for getAllFeatureVariables', () => {
1081+
it('cannot use pre-set and override user for getAllFeatureVariables', async () => {
10821082
const mockFn = mockInnerClient.getAllFeatureVariables as jest.Mock;
10831083
mockFn.mockReturnValue({
10841084
bvar: true,
@@ -1092,7 +1092,7 @@ describe('ReactSDKClient', () => {
10921092
const instance = createInstance(config);
10931093
// @ts-ignore
10941094
instance._client = null;
1095-
instance.setUser({
1095+
await instance.setUser({
10961096
id: 'user1',
10971097
attributes: {
10981098
foo: 'bar',
@@ -1111,7 +1111,7 @@ describe('ReactSDKClient', () => {
11111111
expect(result).toEqual({});
11121112
});
11131113

1114-
it('returns an object with variables of all types returned from the inner sdk ', () => {
1114+
it('returns an object with variables of all types returned from the inner sdk ', async () => {
11151115
const anyClient = mockInnerClient.getAllFeatureVariables as jest.Mock;
11161116
anyClient.mockReturnValue({
11171117
bvar: true,
@@ -1123,7 +1123,7 @@ describe('ReactSDKClient', () => {
11231123
},
11241124
});
11251125
const instance = createInstance(config);
1126-
instance.setUser({
1126+
await instance.setUser({
11271127
id: 'user1123',
11281128
});
11291129
const result = instance.getAllFeatureVariables('feat1', 'user1');
@@ -1138,7 +1138,7 @@ describe('ReactSDKClient', () => {
11381138
});
11391139
});
11401140

1141-
it('can use pre-set and override user for getAllFeatureVariables', () => {
1141+
it('can use pre-set and override user for getAllFeatureVariables', async () => {
11421142
const mockFn = mockInnerClient.getAllFeatureVariables as jest.Mock;
11431143
mockFn.mockReturnValue({
11441144
bvar: true,
@@ -1150,7 +1150,7 @@ describe('ReactSDKClient', () => {
11501150
},
11511151
});
11521152
const instance = createInstance(config);
1153-
instance.setUser({
1153+
await instance.setUser({
11541154
id: 'user1',
11551155
attributes: {
11561156
foo: 'bar',
@@ -1215,7 +1215,7 @@ describe('ReactSDKClient', () => {
12151215
});
12161216

12171217
it('should return false if fetch fails', async () => {
1218-
instance.setUser({
1218+
await instance.setUser({
12191219
id: 'user1',
12201220
});
12211221

@@ -1226,7 +1226,7 @@ describe('ReactSDKClient', () => {
12261226
});
12271227

12281228
it('should return true if fetch successful', async () => {
1229-
instance.setUser({
1229+
await instance.setUser({
12301230
id: 'user1',
12311231
});
12321232

@@ -1239,9 +1239,9 @@ describe('ReactSDKClient', () => {
12391239

12401240
describe('onForcedVariationsUpdate', () => {
12411241
let instance: ReactSDKClient;
1242-
beforeEach(() => {
1242+
beforeEach(async () => {
12431243
instance = createInstance(config);
1244-
instance.setUser({
1244+
await instance.setUser({
12451245
id: 'xxfueaojfe8&86',
12461246
attributes: {
12471247
foo: 'bar',
@@ -1293,10 +1293,10 @@ describe('ReactSDKClient', () => {
12931293
});
12941294

12951295
describe('if Optimizely client is null', () => {
1296-
it('should return false', () => {
1296+
it('should return false', async () => {
12971297
// @ts-ignore
12981298
instance._client = null;
1299-
instance.setUser({
1299+
await instance.setUser({
13001300
id: 'user1',
13011301
});
13021302
const mockFn = mockOptimizelyUserContext.removeAllForcedDecisions as jest.Mock;
@@ -1310,8 +1310,8 @@ describe('ReactSDKClient', () => {
13101310
});
13111311
});
13121312

1313-
it('should return true if user context has been set ', () => {
1314-
instance.setUser({
1313+
it('should return true if user context has been set ', async () => {
1314+
await instance.setUser({
13151315
id: 'user1',
13161316
});
13171317
const mockFn = mockOptimizelyUserContext.removeAllForcedDecisions as jest.Mock;
@@ -1327,9 +1327,9 @@ describe('ReactSDKClient', () => {
13271327

13281328
describe('setForcedDecision', () => {
13291329
let instance: ReactSDKClient;
1330-
beforeEach(() => {
1330+
beforeEach(async () => {
13311331
instance = createInstance(config);
1332-
instance.setUser({
1332+
await instance.setUser({
13331333
id: 'user1',
13341334
attributes: {
13351335
foo: 'bar',
@@ -1436,9 +1436,9 @@ describe('ReactSDKClient', () => {
14361436

14371437
describe('removeForcedDecision', () => {
14381438
let instance: ReactSDKClient;
1439-
beforeEach(() => {
1439+
beforeEach(async () => {
14401440
instance = createInstance(config);
1441-
instance.setUser({
1441+
await instance.setUser({
14421442
id: 'user1',
14431443
attributes: {
14441444
foo: 'bar',

0 commit comments

Comments
 (0)