@@ -19,6 +19,7 @@ describe('Auth0ClientFactory (Native)', () => {
1919
2020 beforeEach ( ( ) => {
2121 jest . clearAllMocks ( ) ;
22+ Auth0ClientFactory . resetClientCache ( ) ;
2223 } ) ;
2324
2425 it ( 'should call validateAuth0Options with the provided options' , ( ) => {
@@ -33,4 +34,32 @@ describe('Auth0ClientFactory (Native)', () => {
3334 expect ( MockNativeAuth0Client ) . toHaveBeenCalledWith ( options ) ;
3435 expect ( client ) . toBeInstanceOf ( MockNativeAuth0Client ) ;
3536 } ) ;
37+
38+ it ( 'should return the same cached client for the same domain+clientId' , ( ) => {
39+ const client1 = Auth0ClientFactory . createClient ( options ) ;
40+ const client2 = Auth0ClientFactory . createClient ( options ) ;
41+
42+ expect ( client1 ) . toBe ( client2 ) ;
43+ expect ( MockNativeAuth0Client ) . toHaveBeenCalledTimes ( 1 ) ;
44+ } ) ;
45+
46+ it ( 'should create separate clients for different domain+clientId' , ( ) => {
47+ const client1 = Auth0ClientFactory . createClient ( options ) ;
48+ const client2 = Auth0ClientFactory . createClient ( {
49+ domain : 'other-tenant.auth0.com' ,
50+ clientId : 'OtherClientId' ,
51+ } ) ;
52+
53+ expect ( client1 ) . not . toBe ( client2 ) ;
54+ expect ( MockNativeAuth0Client ) . toHaveBeenCalledTimes ( 2 ) ;
55+ } ) ;
56+
57+ it ( 'should create a new client after cache is reset' , ( ) => {
58+ const client1 = Auth0ClientFactory . createClient ( options ) ;
59+ Auth0ClientFactory . resetClientCache ( ) ;
60+ const client2 = Auth0ClientFactory . createClient ( options ) ;
61+
62+ expect ( client1 ) . not . toBe ( client2 ) ;
63+ expect ( MockNativeAuth0Client ) . toHaveBeenCalledTimes ( 2 ) ;
64+ } ) ;
3665} ) ;
0 commit comments