@@ -45,8 +45,7 @@ describe('Flagsmith.init', () => {
45
45
const onChange = jest . fn ( )
46
46
const testIdentityWithTraits = `test_identity_with_traits`
47
47
const { flagsmith, initConfig, AsyncStorage, mockFetch} = getFlagsmith ( { onChange, identity :testIdentityWithTraits , traits :{ number_trait :1 , string_trait :"Example" } } )
48
- //@ts -ignore
49
- mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ testIdentityWithTraits } .json` ) } )
48
+ mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ testIdentityWithTraits } .json` , 'utf8' ) } )
50
49
51
50
await flagsmith . init ( initConfig ) ;
52
51
@@ -73,38 +72,32 @@ describe('Flagsmith.init', () => {
73
72
test ( 'should reject initialize with identity bad key' , async ( ) => {
74
73
const onChange = jest . fn ( )
75
74
const { flagsmith, initConfig, mockFetch} = getFlagsmith ( { onChange, environmentID :"bad" } )
76
- //@ts -ignore
77
- mockFetch . mockResolvedValueOnce ( async ( ) => { return { status : 404 } } )
75
+ mockFetch . mockResolvedValueOnce ( { status : 404 , text : async ( ) => '' } )
78
76
await expect ( flagsmith . init ( initConfig ) ) . rejects . toThrow ( Error ) ;
79
77
} ) ;
80
78
test ( 'identifying with new identity should not carry over previous traits for different identity' , async ( ) => {
81
79
const onChange = jest . fn ( )
82
80
const identityA = `test_identity_a`
83
81
const identityB = `test_identity_b`
84
82
const { flagsmith, initConfig, mockFetch} = getFlagsmith ( { onChange, identity :identityA , traits : { a :`example` } } )
85
- //@ts -ignore
86
- mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ identityA } .json` ) } )
83
+ mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ identityA } .json` , 'utf8' ) } )
87
84
await flagsmith . init ( initConfig ) ;
88
85
expect ( flagsmith . getTrait ( "a" ) ) . toEqual ( `example` )
89
- //@ts -ignore
90
- mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ identityB } .json` ) } )
86
+ mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ identityB } .json` , 'utf8' ) } )
91
87
await flagsmith . identify ( identityB )
92
88
expect ( flagsmith . getTrait ( "a" ) ) . toEqual ( undefined )
93
- //@ts -ignore
94
- mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ identityA } .json` ) } )
89
+ mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ identityA } .json` , 'utf8' ) } )
95
90
await flagsmith . identify ( identityA )
96
91
expect ( flagsmith . getTrait ( "a" ) ) . toEqual ( `example` )
97
- //@ts -ignore
98
- mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ identityB } .json` ) } )
92
+ mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ identityB } .json` , 'utf8' ) } )
99
93
await flagsmith . identify ( identityB )
100
94
expect ( flagsmith . getTrait ( "a" ) ) . toEqual ( undefined )
101
95
} ) ;
102
96
test ( 'identifying with transient identity should request the API correctly' , async ( ) => {
103
97
const onChange = jest . fn ( )
104
98
const testTransientIdentity = `test_transient_identity`
105
99
const { flagsmith, initConfig, mockFetch} = getFlagsmith ( { onChange, identity : { identifier : testTransientIdentity , transient : true } } )
106
- //@ts -ignore
107
- mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ testTransientIdentity } .json` ) } )
100
+ mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ testTransientIdentity } .json` , 'utf8' ) } )
108
101
await flagsmith . init ( initConfig ) ;
109
102
expect ( mockFetch ) . toHaveBeenCalledWith ( `https://edge.api.flagsmith.com/api/v1/identities/?identifier=${ testTransientIdentity } &transient=true` ,
110
103
expect . objectContaining ( { method : 'GET' } ) ,
@@ -116,8 +109,7 @@ describe('Flagsmith.init', () => {
116
109
const { flagsmith, initConfig, mockFetch} = getFlagsmith ( { onChange, identity : testIdentityWithTransientTraits ,
117
110
traits : { number_trait :1 , string_trait :"Example" , transient_trait :{ transient :true , value :"Example" } }
118
111
} )
119
- //@ts -ignore
120
- mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ testIdentityWithTransientTraits } .json` ) } )
112
+ mockFetch . mockResolvedValueOnce ( { status : 200 , text : ( ) => fs . readFile ( `./test/data/identities_${ testIdentityWithTransientTraits } .json` , 'utf8' ) } )
121
113
await flagsmith . init ( initConfig ) ;
122
114
expect ( mockFetch ) . toHaveBeenCalledWith ( 'https://edge.api.flagsmith.com/api/v1/identities/' ,
123
115
expect . objectContaining ( { method : 'POST' , body : JSON . stringify ( {
0 commit comments