55 EvaluationContext ,
66 EvaluationDetails ,
77 FlagNotFoundError ,
8+ Hook ,
89 JsonArray ,
910 JsonObject ,
1011 JsonValue ,
@@ -18,6 +19,8 @@ import {
1819 TransactionContextPropagator ,
1920} from '../src' ;
2021import { OpenFeatureClient } from '../src/client/internal/open-feature-client' ;
22+ import { isDeepStrictEqual } from 'node:util' ;
23+ import { HookContext } from '@openfeature/core' ;
2124
2225const BOOLEAN_VALUE = true ;
2326const STRING_VALUE = 'val' ;
@@ -740,9 +743,35 @@ describe('OpenFeatureClient', () => {
740743 // Set Client Context
741744 const client = OpenFeature . getClient ( 'contextual' , 'test' , clientContext ) ;
742745 // Set Hook Context
743- client . addHooks ( { before : ( ) => beforeHookContext } ) ;
746+ const hook = {
747+ before : jest . fn ( ( hookContext : HookContext ) => {
748+ // we have to put this assertion here because of limitations in jest with expect.objectContaining and mutability
749+ if ( isDeepStrictEqual ( hookContext . context , {
750+ ...globalContext ,
751+ ...transactionContext ,
752+ ...clientContext ,
753+ ...invocationContext ,
754+ // before hook context should be missing here (and not overridden)
755+ } ) ) {
756+ return beforeHookContext ;
757+ }
758+ } ) ,
759+ after : jest . fn ( ( hookContext : HookContext ) => {
760+ // we have to put this assertion here because of limitations in jest with expect.objectContaining and mutability
761+ if ( isDeepStrictEqual ( hookContext . context , {
762+ ...globalContext ,
763+ ...transactionContext ,
764+ ...clientContext ,
765+ ...invocationContext ,
766+ ...beforeHookContext ,
767+ } ) ) {
768+ return beforeHookContext ;
769+ }
770+ } ) ,
771+ } as unknown as Hook ;
772+
773+ await client . getBooleanValue ( flagKey , defaultValue , invocationContext , { hooks : [ hook ] } ) ;
744774
745- await client . getBooleanValue ( flagKey , defaultValue , invocationContext ) ;
746775 expect ( provider . resolveBooleanEvaluation ) . toHaveBeenCalledWith (
747776 expect . anything ( ) ,
748777 expect . anything ( ) ,
0 commit comments