@@ -1133,13 +1133,17 @@ describe("Multi-system KoQ registry", () => {
11331133 await qf . addFormattingSpecsToRegistry ( { name : "TestKoQ.LENGTH" , persistenceUnitName : "Units.M" , formatProps : simpleDecimalFormat , system : "imperial" } ) ;
11341134 await qf . addFormattingSpecsToRegistry ( { name : "TestKoQ.LENGTH" , persistenceUnitName : "Units.M" , formatProps : simpleDecimalFormat , system : "metric" } ) ;
11351135
1136- let handle : ReturnType < typeof qf . getFormatSpecHandle > ;
1137- const observedSpecs : FormatterSpec [ ] = [ ] ;
1138- qf . onFormattingReady . addListener ( ( ) => {
1139- observedSpecs . push ( handle . formatterSpec ! ) ;
1136+ const handleRef : { current : ReturnType < typeof qf . getFormatSpecHandle > | undefined } = { current : undefined } ;
1137+ const observedSpecs : Array < FormatterSpec | undefined > = [ ] ;
1138+ const removeReadyListener = qf . onFormattingReady . addListener ( ( ) => {
1139+ if ( ! handleRef . current )
1140+ throw new Error ( "Expected FormatSpecHandle to be created before onFormattingReady fired" ) ;
1141+
1142+ observedSpecs . push ( handleRef . current . formatterSpec ) ;
11401143 } ) ;
11411144
1142- handle = qf . getFormatSpecHandle ( "TestKoQ.LENGTH" , "Units.M" ) ;
1145+ const handle = qf . getFormatSpecHandle ( "TestKoQ.LENGTH" , "Units.M" ) ;
1146+ handleRef . current = handle ;
11431147 const imperialFormatterSpec = qf . getSpecsByNameAndUnit ( {
11441148 name : "TestKoQ.LENGTH" ,
11451149 persistenceUnitName : "Units.M" ,
@@ -1160,6 +1164,8 @@ describe("Multi-system KoQ registry", () => {
11601164 expect ( observedSpecs ) . toHaveLength ( 1 ) ;
11611165 expect ( observedSpecs [ 0 ] ) . toBe ( metricFormatterSpec ) ;
11621166 expect ( observedSpecs [ 0 ] ) . not . toBe ( imperialFormatterSpec ) ;
1167+
1168+ removeReadyListener ( ) ;
11631169 handle [ Symbol . dispose ] ( ) ;
11641170 } ) ;
11651171} ) ;
0 commit comments