@@ -18,7 +18,7 @@ import {
1818 TEST_ID_TOKEN
1919} from '../constants' ;
2020import { DEFAULT_AUDIENCE } from '../../src/constants' ;
21- import { InvalidConfigurationError , MfaRequiredError } from '../../src/errors' ;
21+ import { InvalidConfigurationError } from '../../src/errors' ;
2222import { fetchResponse } from './helpers' ;
2323
2424jest . mock ( 'es-cookie' ) ;
@@ -596,12 +596,18 @@ describe('Auth0Client', () => {
596596
597597 it ( 'uses options.refresh_token directly for refresh_token grant without hitting the cache' , async ( ) => {
598598 // The refactored ?? path: options.refresh_token is set on the refresh_token grant,
599- // so the cache lookup branch must NOT run — the token on options is used as-is.
599+ // so the cache lookup inside _requestToken must NOT fire — options.refresh_token
600+ // short-circuits the ?? before the cache is read.
601+ //
602+ // Verifiable because _getTokenUsingRefreshToken calls cacheManager.get exactly once
603+ // (to retrieve the cached RT before the exchange). A second call would mean the
604+ // ?? fallback ran — which must NOT happen when options.refresh_token is present.
600605 const auth0 = setup ( onlineConfig as any ) ;
601606 await loginWithRedirect ( auth0 ) ;
602607 mockFetch . mockReset ( ) ;
603608
604- // Force-refresh: server returns no refresh_token (non-rotating ORT behaviour)
609+ const cacheGetSpy = jest . spyOn ( ( auth0 as any ) . cacheManager , 'get' ) ;
610+
605611 mockFetch . mockResolvedValueOnce (
606612 fetchResponse ( true , {
607613 id_token : TEST_ID_TOKEN ,
@@ -615,8 +621,12 @@ describe('Auth0Client', () => {
615621
616622 await auth0 . getTokenSilently ( { cacheMode : 'off' } ) ;
617623
618- // ORT from the original login (TEST_REFRESH_TOKEN) must survive in cache —
619- // it was on options.refresh_token and ?? short-circuits before the cache lookup.
624+ // _getTokenUsingRefreshToken calls get() once. The ORT carry-forward in
625+ // _requestToken must NOT add a second call — options.refresh_token is set
626+ // so ?? resolves without reaching the cache.
627+ expect ( cacheGetSpy ) . toHaveBeenCalledTimes ( 1 ) ;
628+
629+ // And the ORT must still be in the cache after the refresh.
620630 const rt = getCacheEntries ( ) . map ( e => e ?. body ?. refresh_token ) . find ( Boolean ) ;
621631 expect ( rt ) . toBe ( TEST_REFRESH_TOKEN ) ;
622632 } ) ;
0 commit comments