11import { EventEmitter } from 'node:events' ;
22import { get } from 'svelte/store' ;
3- import { afterAll , afterEach , beforeEach , describe , expect , it , Mock , vi } from 'vitest' ;
3+ import { afterEach , beforeEach , describe , expect , it , Mock , vi } from 'vitest' ;
44
55import { initialize , LDClient } from '@launchdarkly/js-client-sdk' ;
66
@@ -62,7 +62,7 @@ describe('launchDarkly', () => {
6262
6363 it ( 'should set the loading status to false when the client is ready' , async ( ) => {
6464 const { initializing } = ld ;
65- ld . initialize ( 'clientId' ) ;
65+ ld . initialize ( clientSideID ) ;
6666
6767 expect ( get ( initializing ) ) . toBe ( true ) ; // should be true before the ready event is emitted
6868 mockLDEventEmitter . emit ( 'ready' ) ;
@@ -71,16 +71,16 @@ describe('launchDarkly', () => {
7171 } ) ;
7272
7373 it ( 'should initialize the LaunchDarkly SDK instance' , ( ) => {
74- ld . initialize ( 'clientId' ) ;
74+ ld . initialize ( clientSideID ) ;
7575
76- expect ( initialize ) . toHaveBeenCalledWith ( 'clientId ' ) ;
76+ expect ( initialize ) . toHaveBeenCalledWith ( 'test-client-side-id ' ) ;
7777 } ) ;
7878
7979 it ( 'should register function that gets flag values when client is ready' , ( ) => {
8080 const newFlags = { ...rawFlags , 'new-flag' : true } ;
8181 const allFlagsSpy = vi . spyOn ( mockLDClient , 'allFlags' ) . mockReturnValue ( newFlags ) ;
8282
83- ld . initialize ( 'clientId' ) ;
83+ ld . initialize ( clientSideID ) ;
8484 mockLDEventEmitter . emit ( 'ready' ) ;
8585
8686 expect ( allFlagsSpy ) . toHaveBeenCalledOnce ( ) ;
@@ -91,7 +91,7 @@ describe('launchDarkly', () => {
9191 const changedFlags = { ...rawFlags , 'changed-flag' : true } ;
9292 const allFlagsSpy = vi . spyOn ( mockLDClient , 'allFlags' ) . mockReturnValue ( changedFlags ) ;
9393
94- ld . initialize ( 'clientId' ) ;
94+ ld . initialize ( clientSideID ) ;
9595 mockLDEventEmitter . emit ( 'change' ) ;
9696
9797 expect ( allFlagsSpy ) . toHaveBeenCalledOnce ( ) ;
@@ -161,21 +161,29 @@ describe('launchDarkly', () => {
161161 // TODO: fix these tests
162162 // describe('isOn function', () => {
163163 // const ld = LD;
164- // // beforeEach(() => {
165- // // mockInitialize.mockImplementation(() => mockLDClient);
166- // // mockAllFlags.mockImplementation(() => rawFlags);
167- // // });
164+
165+ // beforeEach(() => {
166+ // // mocks the initialize function to return the mockLDClient
167+ // (initialize as Mock<typeof initialize>).mockReturnValue(
168+ // mockLDClient as unknown as LDClient,
169+ // );
170+ // });
171+
172+ // afterEach(() => {
173+ // vi.clearAllMocks();
174+ // mockLDEventEmitter.removeAllListeners();
175+ // });
168176
169177 // it('should return true if the flag is on', () => {
170178 // const flagKey = 'test-flag';
171- // ld.initialize(clientSideID, { key: 'user1' } );
179+ // ld.initialize(clientSideID);
172180
173181 // expect(ld.isOn(flagKey)).toBe(true);
174182 // });
175183
176184 // it('should return false if the flag is off', () => {
177185 // const flagKey = 'test-flag';
178- // ld.initialize(clientSideID, { key: 'user1' } );
186+ // ld.initialize(clientSideID);
179187
180188 // mockAllFlags.mockReturnValue({ ...rawFlags, 'test-flag': false });
181189
0 commit comments