@@ -3,7 +3,6 @@ import { EnvironmentDataPollingManager } from '../../sdk/polling_manager.js';
33import {
44 environmentJSON ,
55 environmentModel ,
6- flagsJSON ,
76 flagsmith ,
87 fetch ,
98 offlineEnvironmentJSON ,
@@ -21,7 +20,6 @@ beforeEach(() => {
2120} ) ;
2221
2322test ( 'test_flagsmith_starts_polling_manager_on_init_if_enabled' , ( ) => {
24- fetch . mockResolvedValue ( new Response ( environmentJSON ) ) ;
2523 new Flagsmith ( {
2624 environmentKey : 'ser.key' ,
2725 enableLocalEvaluation : true
@@ -30,7 +28,6 @@ test('test_flagsmith_starts_polling_manager_on_init_if_enabled', () => {
3028} ) ;
3129
3230test ( 'test_flagsmith_local_evaluation_key_required' , ( ) => {
33- fetch . mockResolvedValue ( new Response ( environmentJSON ) ) ;
3431 expect ( ( ) => {
3532 new Flagsmith ( {
3633 environmentKey : 'bad.key' ,
@@ -40,16 +37,17 @@ test('test_flagsmith_local_evaluation_key_required', () => {
4037} ) ;
4138
4239test ( 'test_update_environment_sets_environment' , async ( ) => {
43- fetch . mockResolvedValue ( new Response ( environmentJSON ) ) ;
44- const flg = flagsmith ( ) ;
40+ const flg = flagsmith ( {
41+ environmentKey : 'ser.key' ,
42+ } ) ;
4543 const model = environmentModel ( JSON . parse ( environmentJSON ) ) ;
4644 expect ( await flg . getEnvironment ( ) ) . toStrictEqual ( model ) ;
4745} ) ;
4846
4947test ( 'test_set_agent_options' , async ( ) => {
5048 const agent = new Agent ( { } )
5149
52- fetch . mockImplementation ( ( url , options ) => {
50+ fetch . mockImplementationOnce ( ( url , options ) => {
5351 //@ts -ignore I give up
5452 if ( options . dispatcher !== agent ) {
5553 throw new Error ( "Agent has not been set on retry fetch" )
@@ -65,7 +63,6 @@ test('test_set_agent_options', async () => {
6563} ) ;
6664
6765test ( 'test_get_identity_segments' , async ( ) => {
68- fetch . mockResolvedValue ( new Response ( environmentJSON ) ) ;
6966 const flg = flagsmith ( {
7067 environmentKey : 'ser.key' ,
7168 enableLocalEvaluation : true
@@ -78,7 +75,6 @@ test('test_get_identity_segments', async () => {
7875
7976
8077test ( 'test_get_identity_segments_empty_without_local_eval' , async ( ) => {
81- fetch . mockResolvedValue ( new Response ( environmentJSON ) ) ;
8278 const flg = new Flagsmith ( {
8379 environmentKey : 'ser.key' ,
8480 enableLocalEvaluation : false
@@ -88,8 +84,6 @@ test('test_get_identity_segments_empty_without_local_eval', async () => {
8884} ) ;
8985
9086test ( 'test_update_environment_uses_req_when_inited' , async ( ) => {
91- fetch . mockResolvedValue ( new Response ( environmentJSON ) ) ;
92-
9387 const flg = flagsmith ( {
9488 environmentKey : 'ser.key' ,
9589 enableLocalEvaluation : true ,
@@ -103,7 +97,6 @@ test('test_update_environment_uses_req_when_inited', async () => {
10397} ) ;
10498
10599test ( 'test_isFeatureEnabled_environment' , async ( ) => {
106- fetch . mockResolvedValue ( new Response ( environmentJSON ) ) ;
107100 const defaultFlag = new DefaultFlag ( 'some-default-value' , true ) ;
108101
109102 const defaultFlagHandler = ( featureName : string ) => defaultFlag ;
@@ -121,9 +114,7 @@ test('test_isFeatureEnabled_environment', async () => {
121114} ) ;
122115
123116test ( 'test_fetch_recovers_after_single_API_error' , async ( ) => {
124- fetch
125- . mockRejectedValue ( 'Error during fetching the API response' )
126- . mockResolvedValue ( new Response ( flagsJSON ) ) ;
117+ fetch . mockRejectedValue ( 'Error during fetching the API response' )
127118 const flg = flagsmith ( {
128119 environmentKey : 'key' ,
129120 } ) ;
@@ -157,8 +148,9 @@ test.each([
157148
158149test ( 'default flag handler used when timeout occurs' , async ( ) => {
159150 fetch . mockImplementation ( async ( ...args ) => {
160- await sleep ( 10000 )
161- return fetch ( ...args )
151+ const forever = new Promise ( ( ) => { } )
152+ await forever
153+ throw new Error ( 'waited forever' )
162154 } ) ;
163155
164156 const defaultFlag = new DefaultFlag ( 'some-default-value' , true ) ;
0 commit comments