@@ -2,7 +2,7 @@ import { jest } from '@jest/globals';
22
33import { LDLogger } from '@launchdarkly/js-client-sdk-common' ;
44
5- import validateOptions , { filterToBaseOptions } from '../src/options' ;
5+ import validateBrowserOptions , { filterToBaseOptionsWithDefaults } from '../src/options' ;
66
77let logger : LDLogger ;
88
@@ -16,7 +16,7 @@ beforeEach(() => {
1616} ) ;
1717
1818it ( 'logs no warnings when all configuration is valid' , ( ) => {
19- validateOptions (
19+ validateBrowserOptions (
2020 {
2121 fetchGoals : true ,
2222 eventUrlTransformer : ( url : string ) => url ,
@@ -31,7 +31,7 @@ it('logs no warnings when all configuration is valid', () => {
3131} ) ;
3232
3333it ( 'warns for invalid configuration' , ( ) => {
34- validateOptions (
34+ validateBrowserOptions (
3535 {
3636 // @ts -ignore
3737 fetchGoals : 'yes' ,
@@ -50,8 +50,8 @@ it('warns for invalid configuration', () => {
5050 ) ;
5151} ) ;
5252
53- it ( 'applies default options' , ( ) => {
54- const opts = validateOptions ( { } , logger ) ;
53+ it ( 'applies default browser-specific options' , ( ) => {
54+ const opts = validateBrowserOptions ( { } , logger ) ;
5555
5656 expect ( opts . fetchGoals ) . toBe ( true ) ;
5757 expect ( opts . eventUrlTransformer ) . toBeDefined ( ) ;
@@ -69,9 +69,24 @@ it('filters to base options', () => {
6969 eventUrlTransformer : ( url : string ) => url ,
7070 } ;
7171
72- const baseOpts = filterToBaseOptions ( opts ) ;
72+ const baseOpts = filterToBaseOptionsWithDefaults ( opts ) ;
7373 expect ( baseOpts . debug ) . toBe ( false ) ;
74- expect ( Object . keys ( baseOpts ) . length ) . toEqual ( 1 ) ;
74+ expect ( Object . keys ( baseOpts ) . length ) . toEqual ( 2 ) ;
7575 expect ( baseOpts ) . not . toHaveProperty ( 'fetchGoals' ) ;
7676 expect ( baseOpts ) . not . toHaveProperty ( 'eventUrlTransformer' ) ;
77+ expect ( baseOpts . flushInterval ) . toEqual ( 2 ) ;
78+ } ) ;
79+
80+ it ( 'applies default overrides to common config flushInterval' , ( ) => {
81+ const opts = { } ;
82+ const result = filterToBaseOptionsWithDefaults ( opts ) ;
83+ expect ( result . flushInterval ) . toEqual ( 2 ) ;
84+ } ) ;
85+
86+ it ( 'does not override common config flushInterval if it is set' , ( ) => {
87+ const opts = {
88+ flushInterval : 15 ,
89+ } ;
90+ const result = filterToBaseOptionsWithDefaults ( opts ) ;
91+ expect ( result . flushInterval ) . toEqual ( 15 ) ;
7792} ) ;
0 commit comments