11// Sample test
22import { getFlagsmith } from './test-constants' ;
3- import { IFlagsmith } from '../types' ;
3+ import { IFlagsmith , IFlagsmithFeature } from '../types' ;
44
55describe ( 'Flagsmith Types' , ( ) => {
66
@@ -20,13 +20,45 @@ describe('Flagsmith Types', () => {
2020 typedFlagsmith . getValue ( "flag2" )
2121 } ) ;
2222 test ( 'should allow supplying interface generics to a flagsmith instance' , async ( ) => {
23- const { flagsmith, } = getFlagsmith ( { } ) ;
23+ const { flagsmith } = getFlagsmith ( { } ) ;
2424 const typedFlagsmith = flagsmith as IFlagsmith <
2525 {
2626 stringFlag : string
2727 numberFlag : number
2828 objectFlag : { first_name : string }
2929 } >
30+ typedFlagsmith . init ( {
31+ environmentID : "test" ,
32+ defaultFlags : {
33+ stringFlag : {
34+ id : 1 ,
35+ enabled : true ,
36+ value : "string_value"
37+ } ,
38+ numberFlag : {
39+ id : 2 ,
40+ enabled : true ,
41+ value : 123
42+ } ,
43+ objectFlag : {
44+ id : 3 ,
45+ enabled : true ,
46+ value : JSON . stringify ( { first_name : "John" } )
47+ }
48+ } ,
49+ onChange : ( previousFlags ) => {
50+ //eslint-disable-next-line @typescript-eslint/no-unused-vars
51+ const previousStringFlag = previousFlags ?. stringFlag
52+ //eslint-disable-next-line @typescript-eslint/no-unused-vars
53+ const previousNumberFlag = previousFlags ?. numberFlag
54+ //eslint-disable-next-line @typescript-eslint/no-unused-vars
55+ const previousObjectFlag = previousFlags ?. objectFlag
56+ //@ts -expect-error - flag does not exist
57+ //eslint-disable-next-line @typescript-eslint/no-unused-vars
58+ const previousNonExistingFlag = previousFlags ?. nonExistingFlag
59+ }
60+ } )
61+
3062 //@ts -expect-error - feature not defined
3163 typedFlagsmith . hasFeature ( "fail" )
3264 //@ts -expect-error - feature not defined
@@ -36,6 +68,18 @@ describe('Flagsmith Types', () => {
3668 typedFlagsmith . hasFeature ( "numberFlag" )
3769 typedFlagsmith . getValue ( "stringFlag" )
3870 typedFlagsmith . getValue ( "numberFlag" )
71+
72+ const typedFlags = await typedFlagsmith . getAllFlags ( )
73+ //eslint-disable-next-line @typescript-eslint/no-unused-vars
74+ const asString = typedFlags . stringFlag
75+ //eslint-disable-next-line @typescript-eslint/no-unused-vars
76+ const asNumber = typedFlags . numberFlag
77+ //eslint-disable-next-line @typescript-eslint/no-unused-vars
78+ const asObject = typedFlags . objectFlag
79+
80+ // @ts -expect-error - invalid does not exist on type
81+ //eslint-disable-next-line @typescript-eslint/no-unused-vars
82+ const asNonExisting = typedFlags . nonExistingFlag
3983
4084 //eslint-disable-next-line @typescript-eslint/no-unused-vars
4185 const stringFlag : string | null = typedFlagsmith . getValue ( "stringFlag" )
@@ -44,7 +88,7 @@ describe('Flagsmith Types', () => {
4488 //eslint-disable-next-line @typescript-eslint/no-unused-vars
4589 const firstName : string | undefined = typedFlagsmith . getValue ( "objectFlag" ) ?. first_name
4690
47- // @ts -expect-error - invalid does not exist on type announcement
91+ // @ts -expect-error - invalid does not exist on type
4892 //eslint-disable-next-line @typescript-eslint/no-unused-vars
4993 const invalidPointer : string = typedFlagsmith . getValue ( "objectFlag" ) ?. invalid
5094
0 commit comments