@@ -2,11 +2,11 @@ import { EventEmitter } from 'node:events';
22import { get } from 'svelte/store' ;
33import { afterEach , beforeEach , describe , expect , it , Mock , vi } from 'vitest' ;
44
5- import { initialize , LDClient } from '@launchdarkly/js-client-sdk/compat ' ;
5+ import { createClient , LDClient } from '@launchdarkly/js-client-sdk' ;
66
77import { LD } from '../../../src/lib/client/SvelteLDClient' ;
88
9- vi . mock ( '@launchdarkly/js-client-sdk/compat ' , { spy : true } ) ;
9+ vi . mock ( '@launchdarkly/js-client-sdk' , { spy : true } ) ;
1010
1111const clientSideID = 'test-client-side-id' ;
1212const rawFlags = { 'test-flag' : true , 'another-test-flag' : 'flag-value' } ;
@@ -21,6 +21,7 @@ const mockLDClient = {
2121 allFlags : vi . fn ( ) . mockReturnValue ( rawFlags ) ,
2222 variation : vi . fn ( ( _ , defaultValue ) => defaultValue ) ,
2323 identify : vi . fn ( ) ,
24+ start : vi . fn ( ) ,
2425} ;
2526
2627describe ( 'launchDarkly' , ( ) => {
@@ -40,8 +41,7 @@ describe('launchDarkly', () => {
4041 const ld = LD ;
4142
4243 beforeEach ( ( ) => {
43- // mocks the initialize function to return the mockLDClient
44- ( initialize as Mock < typeof initialize > ) . mockReturnValue (
44+ ( createClient as Mock < typeof createClient > ) . mockReturnValue (
4545 mockLDClient as unknown as LDClient ,
4646 ) ;
4747 } ) ;
@@ -66,23 +66,23 @@ describe('launchDarkly', () => {
6666 ld . initialize ( clientSideID , mockContext ) ;
6767
6868 expect ( get ( initializing ) ) . toBe ( true ) ; // should be true before the ready event is emitted
69- mockLDEventEmitter . emit ( 'ready ' ) ;
69+ mockLDEventEmitter . emit ( 'initialized ' ) ;
7070
7171 expect ( get ( initializing ) ) . toBe ( false ) ;
7272 } ) ;
7373
7474 it ( 'should initialize the LaunchDarkly SDK instance' , ( ) => {
7575 ld . initialize ( clientSideID , mockContext ) ;
7676
77- expect ( initialize ) . toHaveBeenCalledWith ( 'test-client-side-id' , mockContext ) ;
77+ expect ( createClient ) . toHaveBeenCalledWith ( 'test-client-side-id' , mockContext , undefined ) ;
7878 } ) ;
7979
8080 it ( 'should register function that gets flag values when client is ready' , ( ) => {
8181 const newFlags = { ...rawFlags , 'new-flag' : true } ;
8282 const allFlagsSpy = vi . spyOn ( mockLDClient , 'allFlags' ) . mockReturnValue ( newFlags ) ;
8383
8484 ld . initialize ( clientSideID , mockContext ) ;
85- mockLDEventEmitter . emit ( 'ready ' ) ;
85+ mockLDEventEmitter . emit ( 'initialized ' ) ;
8686
8787 expect ( allFlagsSpy ) . toHaveBeenCalledOnce ( ) ;
8888 expect ( allFlagsSpy ) . toHaveReturnedWith ( newFlags ) ;
@@ -104,8 +104,7 @@ describe('launchDarkly', () => {
104104 const ld = LD ;
105105
106106 beforeEach ( ( ) => {
107- // mocks the initialize function to return the mockLDClient
108- ( initialize as Mock < typeof initialize > ) . mockReturnValue (
107+ ( createClient as Mock < typeof createClient > ) . mockReturnValue (
109108 mockLDClient as unknown as LDClient ,
110109 ) ;
111110 } ) ;
@@ -166,8 +165,7 @@ describe('launchDarkly', () => {
166165 const ld = LD ;
167166
168167 beforeEach ( ( ) => {
169- // mocks the initialize function to return the mockLDClient
170- ( initialize as Mock < typeof initialize > ) . mockReturnValue (
168+ ( createClient as Mock < typeof createClient > ) . mockReturnValue (
171169 mockLDClient as unknown as LDClient ,
172170 ) ;
173171 } ) ;
@@ -191,8 +189,7 @@ describe('launchDarkly', () => {
191189 const ld = LD ;
192190
193191 beforeEach ( ( ) => {
194- // mocks the initialize function to return the mockLDClient
195- ( initialize as Mock < typeof initialize > ) . mockReturnValue (
192+ ( createClient as Mock < typeof createClient > ) . mockReturnValue (
196193 mockLDClient as unknown as LDClient ,
197194 ) ;
198195 } ) ;
0 commit comments