@@ -33,7 +33,7 @@ describe('launchDarkly', () => {
3333 expect ( ld ) . toHaveProperty ( 'initialize' ) ;
3434 expect ( ld ) . toHaveProperty ( 'initializing' ) ;
3535 expect ( ld ) . toHaveProperty ( 'watch' ) ;
36- expect ( ld ) . toHaveProperty ( 'isOn ' ) ;
36+ expect ( ld ) . toHaveProperty ( 'useFlag ' ) ;
3737 } ) ;
3838
3939 describe ( 'initialize' , async ( ) => {
@@ -55,7 +55,7 @@ describe('launchDarkly', () => {
5555 const flagKey = 'test-flag' ;
5656 const user = { key : 'user1' } ;
5757
58- expect ( ( ) => ld . isOn ( flagKey ) ) . toThrow ( 'LaunchDarkly client not initialized' ) ;
58+ expect ( ( ) => ld . useFlag ( flagKey , true ) ) . toThrow ( 'LaunchDarkly client not initialized' ) ;
5959 await expect ( ( ) => ld . identify ( user ) ) . rejects . toThrow (
6060 'LaunchDarkly client not initialized' ,
6161 ) ;
@@ -162,98 +162,54 @@ describe('launchDarkly', () => {
162162 } ) ;
163163 } ) ;
164164
165- // TODO: fix these tests
166- // describe('isOn function', () => {
167- // const ld = LD;
168-
169- // beforeEach(() => {
170- // // mocks the initialize function to return the mockLDClient
171- // (initialize as Mock<typeof initialize>).mockReturnValue(
172- // mockLDClient as unknown as LDClient,
173- // );
174- // });
175-
176- // afterEach(() => {
177- // vi.clearAllMocks();
178- // mockLDEventEmitter.removeAllListeners();
179- // });
180-
181- // it('should return true if the flag is on', () => {
182- // const flagKey = 'test-flag';
183- // ld.initialize(clientSideID);
184-
185- // expect(ld.isOn(flagKey)).toBe(true);
186- // });
187-
188- // it('should return false if the flag is off', () => {
189- // const flagKey = 'test-flag';
190- // ld.initialize(clientSideID);
191-
192- // mockAllFlags.mockReturnValue({ ...rawFlags, 'test-flag': false });
193-
194- // // dispatch a change event on ldClient
195- // const changeCallback = mockLDClient.on.mock.calls[0][1];
196- // changeCallback();
197-
198- // expect(ld.isOn(flagKey)).toBe(false);
199- // });
200-
201- // it('should return false if the flag is not found', () => {
202- // const flagKey = 'non-existent-flag';
203- // ld.initialize(clientSideID, { key: 'user1' });
204-
205- // expect(ld.isOn(flagKey)).toBe(false);
206- // });
207- // });
208-
209- // describe('identify function', () => {
210- // const ld = LD;
211- // beforeEach(() => {
212- // mockInitialize.mockImplementation(() => mockLDClient);
213- // mockAllFlags.mockImplementation(() => rawFlags);
214- // });
215-
216- // it('should call the identify method on the LaunchDarkly client', () => {
217- // const user = { key: 'user1' };
218- // ld.initialize(clientSideID, user);
219-
220- // ld.identify(user);
221-
222- // expect(mockLDClient.identify).toHaveBeenCalledWith(user);
223- // });
224- // });
165+ describe ( 'useFlag function' , ( ) => {
166+ const ld = LD ;
225167
226- // describe('flags store', () => {
227- // const ld = LD;
228- // beforeEach(() => {
229- // mockInitialize.mockImplementation(() => mockLDClient);
230- // mockAllFlags.mockImplementation(() => rawFlags );
231- // });
168+ beforeEach ( ( ) => {
169+ // mocks the initialize function to return the mockLDClient
170+ ( initialize as Mock < typeof initialize > ) . mockReturnValue (
171+ mockLDClient as unknown as LDClient ,
172+ ) ;
173+ } ) ;
232174
233- // it('should return a readonly store of the flags', () => {
234- // ld.initialize(clientSideID, { key: 'user1' });
175+ afterEach ( ( ) => {
176+ vi . clearAllMocks ( ) ;
177+ mockLDEventEmitter . removeAllListeners ( ) ;
178+ } ) ;
235179
236- // const { flags } = ld;
180+ it ( 'should return flag value' , ( ) => {
181+ mockLDClient . variation . mockReturnValue ( true ) ;
182+ const flagKey = 'test-flag' ;
183+ ld . initialize ( clientSideID , mockContext ) ;
237184
238- // expect(get(flags)).toEqual(rawFlags);
239- // });
185+ expect ( ld . useFlag ( flagKey , false ) ) . toBe ( true ) ;
186+ expect ( mockLDClient . variation ) . toHaveBeenCalledWith ( flagKey , false ) ;
187+ } ) ;
188+ } ) ;
240189
241- // it('should update the flags store when the flags change ', () => {
242- // ld.initialize(clientSideID, { key: 'user1' }) ;
190+ describe ( 'identify function ', ( ) => {
191+ const ld = LD ;
243192
244- // const { flags } = ld;
193+ beforeEach ( ( ) => {
194+ // mocks the initialize function to return the mockLDClient
195+ ( initialize as Mock < typeof initialize > ) . mockReturnValue (
196+ mockLDClient as unknown as LDClient ,
197+ ) ;
198+ } ) ;
245199
246- // expect(get(flags)).toEqual(rawFlags);
200+ afterEach ( ( ) => {
201+ vi . clearAllMocks ( ) ;
202+ mockLDEventEmitter . removeAllListeners ( ) ;
203+ } ) ;
247204
248- // const newFlags = { 'test-flag': false, 'another-test-flag': true };
249- // mockAllFlags.mockReturnValue(newFlags);
205+ it ( 'should call the identify method on the LaunchDarkly client' , ( ) => {
206+ const user = { key : 'user1' } ;
207+ ld . initialize ( clientSideID , user ) ;
250208
251- // // dispatch a change event on ldClient
252- // const changeCallback = mockLDClient.on.mock.calls[0][1];
253- // changeCallback();
209+ ld . identify ( user ) ;
254210
255- // expect(get(flags)).toEqual(newFlags );
256- // });
257- // });
211+ expect ( mockLDClient . identify ) . toHaveBeenCalledWith ( user ) ;
212+ } ) ;
213+ } ) ;
258214 } ) ;
259215} ) ;
0 commit comments