@@ -343,4 +343,63 @@ describe('PricingTable - plans visibility', () => {
343343 expect ( queryByRole ( 'heading' , { name : 'Test Plan' } ) ) . not . toBeInTheDocument ( ) ;
344344 } ) ;
345345 } ) ;
346+
347+ it ( 'prevents flicker by not showing plans while subscription is loading' , async ( ) => {
348+ const { wrapper, fixtures, props } = await createFixtures ( f => {
349+ f . withUser ( { email_addresses : [ 'test@clerk.com' ] } ) ;
350+ } ) ;
351+
352+ // Provide empty props to the PricingTable context
353+ props . setProps ( { } ) ;
354+
355+ fixtures . clerk . billing . getPlans . mockResolvedValue ( { data : [ testPlan as any ] , total_count : 1 } ) ;
356+
357+ // Create a pending promise and capture its resolver
358+ let resolveSubscription ! : ( value : any ) => void ;
359+ const pendingSubscriptionPromise = new Promise < any > ( resolve => {
360+ resolveSubscription = resolve ;
361+ } ) ;
362+ fixtures . clerk . billing . getSubscription . mockReturnValue ( pendingSubscriptionPromise ) ;
363+
364+ const { queryByRole, findByRole } = render ( < PricingTable /> , { wrapper } ) ;
365+
366+ // Assert no plans render while subscription is pending
367+ await waitFor ( ( ) => {
368+ expect ( queryByRole ( 'heading' , { name : 'Test Plan' } ) ) . not . toBeInTheDocument ( ) ;
369+ } ) ;
370+
371+ // Resolve the subscription with an active subscription object
372+ resolveSubscription ( {
373+ id : 'sub_active' ,
374+ status : 'active' ,
375+ activeAt : new Date ( '2021-01-01' ) ,
376+ createdAt : new Date ( '2021-01-01' ) ,
377+ nextPayment : null ,
378+ pastDueAt : null ,
379+ updatedAt : null ,
380+ subscriptionItems : [
381+ {
382+ id : 'si_active' ,
383+ plan : testPlan ,
384+ createdAt : new Date ( '2021-01-01' ) ,
385+ paymentSourceId : 'src_1' ,
386+ pastDueAt : null ,
387+ canceledAt : null ,
388+ periodStart : new Date ( '2021-01-01' ) ,
389+ periodEnd : new Date ( '2021-01-31' ) ,
390+ planPeriod : 'month' as const ,
391+ status : 'active' as const ,
392+ isFreeTrial : false ,
393+ cancel : jest . fn ( ) ,
394+ pathRoot : '' ,
395+ reload : jest . fn ( ) ,
396+ } ,
397+ ] ,
398+ pathRoot : '' ,
399+ reload : jest . fn ( ) ,
400+ } ) ;
401+
402+ // Assert the plan heading appears after subscription resolves
403+ await findByRole ( 'heading' , { name : 'Test Plan' } ) ;
404+ } ) ;
346405} ) ;
0 commit comments