Skip to content

Commit e1d1079

Browse files
committed
test: adding unit tests for evaluation from bootstrap
1 parent 0b9ed16 commit e1d1079

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/sdk/browser/__tests__/BrowserClient.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,43 @@ describe('given a mock platform for a BrowserClient', () => {
189189
});
190190
});
191191

192+
it('can evaluate flags with bootstrap data before identify completes', async () => {
193+
const client = makeClient(
194+
'client-side-id',
195+
AutoEnvAttributes.Disabled,
196+
{
197+
streaming: false,
198+
logger,
199+
diagnosticOptOut: true,
200+
},
201+
platform,
202+
);
203+
204+
const identifyPromise = client.identify(
205+
{ kind: 'user', key: 'bob' },
206+
{
207+
bootstrap: goodBootstrapDataWithReasons,
208+
},
209+
);
210+
211+
const flagValue = client.jsonVariationDetail('json', undefined);
212+
expect(flagValue).toEqual({
213+
reason: {
214+
kind: 'OFF',
215+
},
216+
value: ['a', 'b', 'c', 'd'],
217+
variationIndex: 1,
218+
});
219+
220+
expect(client.getContext()).toBeUndefined();
221+
222+
// Wait for identify to complete
223+
await identifyPromise;
224+
225+
// Verify that active context is now set
226+
expect(client.getContext()).toEqual({ kind: 'user', key: 'bob' });
227+
});
228+
192229
it('can shed intermediate identify calls', async () => {
193230
const client = makeClient(
194231
'client-side-id',

0 commit comments

Comments
 (0)