@@ -14,7 +14,7 @@ import pkg from '../package.json';
1414import { createWrapper } from './helpers' ;
1515import { Auth0Provider , useAuth0 } from '../src' ;
1616
17- const clientMock = jest . mocked ( new Auth0Client ( { client_id : '' , domain : '' } ) ) ;
17+ const clientMock = jest . mocked ( new Auth0Client ( { clientId : '' , domain : '' } ) ) ;
1818
1919describe ( 'Auth0Provider' , ( ) => {
2020 afterEach ( ( ) => {
@@ -35,21 +35,25 @@ describe('Auth0Provider', () => {
3535 const opts = {
3636 clientId : 'foo' ,
3737 domain : 'bar' ,
38- redirectUri : 'baz' ,
39- maxAge : 'qux' ,
40- extra_param : '__test_extra_param__' ,
38+ authorizationParams : {
39+ redirect_uri : 'baz' ,
40+ max_age : 'qux' ,
41+ extra_param : '__test_extra_param__' ,
42+ } ,
4143 } ;
4244 const wrapper = createWrapper ( opts ) ;
4345 const { waitForNextUpdate } = renderHook ( ( ) => useContext ( Auth0Context ) , {
4446 wrapper,
4547 } ) ;
4648 expect ( Auth0Client ) . toHaveBeenCalledWith (
4749 expect . objectContaining ( {
48- client_id : 'foo' ,
50+ clientId : 'foo' ,
4951 domain : 'bar' ,
50- redirect_uri : 'baz' ,
51- max_age : 'qux' ,
52- extra_param : '__test_extra_param__' ,
52+ authorizationParams : {
53+ redirect_uri : 'baz' ,
54+ max_age : 'qux' ,
55+ extra_param : '__test_extra_param__' ,
56+ } ,
5357 } )
5458 ) ;
5559 await waitForNextUpdate ( ) ;
@@ -228,41 +232,6 @@ describe('Auth0Provider', () => {
228232 expect ( result . current . error ) . not . toBeDefined ( ) ;
229233 } ) ;
230234
231- it ( 'should call through to buildAuthorizeUrl method' , async ( ) => {
232- const wrapper = createWrapper ( ) ;
233- const { waitForNextUpdate, result } = renderHook (
234- ( ) => useContext ( Auth0Context ) ,
235- { wrapper }
236- ) ;
237- await waitForNextUpdate ( ) ;
238- expect ( result . current . buildAuthorizeUrl ) . toBeInstanceOf ( Function ) ;
239-
240- await result . current . buildAuthorizeUrl ( {
241- redirectUri : '__redirect_uri__' ,
242- } ) ;
243- expect ( clientMock . buildAuthorizeUrl ) . toHaveBeenCalledWith ( {
244- redirect_uri : '__redirect_uri__' ,
245- } ) ;
246- } ) ;
247-
248- it ( 'should call through to buildLogoutUrl method' , async ( ) => {
249- const wrapper = createWrapper ( ) ;
250- const { waitForNextUpdate, result } = renderHook (
251- ( ) => useContext ( Auth0Context ) ,
252- { wrapper }
253- ) ;
254- await waitForNextUpdate ( ) ;
255- expect ( result . current . buildLogoutUrl ) . toBeInstanceOf ( Function ) ;
256-
257- const logoutOptions = {
258- returnTo : '/' ,
259- client_id : 'blah' ,
260- federated : false ,
261- } ;
262- result . current . buildLogoutUrl ( logoutOptions ) ;
263- expect ( clientMock . buildLogoutUrl ) . toHaveBeenCalledWith ( logoutOptions ) ;
264- } ) ;
265-
266235 it ( 'should login with a popup' , async ( ) => {
267236 clientMock . getUser . mockResolvedValue ( undefined ) ;
268237 const wrapper = createWrapper ( ) ;
@@ -320,10 +289,14 @@ describe('Auth0Provider', () => {
320289 await waitForNextUpdate ( ) ;
321290 expect ( result . current . loginWithRedirect ) . toBeInstanceOf ( Function ) ;
322291 await result . current . loginWithRedirect ( {
323- redirectUri : '__redirect_uri__' ,
292+ authorizationParams : {
293+ redirect_uri : '__redirect_uri__' ,
294+ } ,
324295 } ) ;
325296 expect ( clientMock . loginWithRedirect ) . toHaveBeenCalledWith ( {
326- redirect_uri : '__redirect_uri__' ,
297+ authorizationParams : {
298+ redirect_uri : '__redirect_uri__' ,
299+ } ,
327300 } ) ;
328301 } ) ;
329302
@@ -346,28 +319,7 @@ describe('Auth0Provider', () => {
346319 expect ( result . current . user ) . toBe ( user ) ;
347320 } ) ;
348321
349- it ( 'should update state for local logouts' , async ( ) => {
350- const user = { name : '__test_user__' } ;
351- clientMock . getUser . mockResolvedValue ( user ) ;
352- const wrapper = createWrapper ( ) ;
353- const { waitForNextUpdate, result } = renderHook (
354- ( ) => useContext ( Auth0Context ) ,
355- { wrapper }
356- ) ;
357- await waitForNextUpdate ( ) ;
358- expect ( result . current . isAuthenticated ) . toBe ( true ) ;
359- expect ( result . current . user ) . toBe ( user ) ;
360- act ( ( ) => {
361- result . current . logout ( { localOnly : true } ) ;
362- } ) ;
363- expect ( clientMock . logout ) . toHaveBeenCalledWith ( {
364- localOnly : true ,
365- } ) ;
366- expect ( result . current . isAuthenticated ) . toBe ( false ) ;
367- expect ( result . current . user ) . toBeUndefined ( ) ;
368- } ) ;
369-
370- it ( 'should update state for local logouts with async cache' , async ( ) => {
322+ it ( 'should update state when using onRedirect' , async ( ) => {
371323 const user = { name : '__test_user__' } ;
372324 clientMock . getUser . mockResolvedValue ( user ) ;
373325 // get logout to return a Promise to simulate async cache.
@@ -380,7 +332,8 @@ describe('Auth0Provider', () => {
380332 await waitForNextUpdate ( ) ;
381333 expect ( result . current . isAuthenticated ) . toBe ( true ) ;
382334 await act ( async ( ) => {
383- await result . current . logout ( { localOnly : true } ) ;
335+ // eslint-disable-next-line @typescript-eslint/no-empty-function
336+ await result . current . logout ( { onRedirect : async ( ) => { } } ) ;
384337 } ) ;
385338 expect ( result . current . isAuthenticated ) . toBe ( false ) ;
386339 } ) ;
@@ -895,15 +848,20 @@ describe('Auth0Provider', () => {
895848 wrapper,
896849 } ) ;
897850
898- await expect (
899- auth0ContextRender . result . current . getIdTokenClaims
900- ) . toThrowError ( 'You forgot to wrap your component in <Auth0Provider>.' ) ;
851+ await act ( async ( ) => {
852+ await expect (
853+ auth0ContextRender . result . current . getIdTokenClaims
854+ ) . toThrowError ( 'You forgot to wrap your component in <Auth0Provider>.' ) ;
855+ } ) ;
901856
902857 const customContextRender = renderHook ( ( ) => useContext ( context ) , {
903858 wrapper,
904859 } ) ;
905860
906- const claims = await customContextRender . result . current . getIdTokenClaims ( ) ;
861+ let claims ;
862+ await act ( async ( ) => {
863+ claims = await customContextRender . result . current . getIdTokenClaims ( ) ;
864+ } ) ;
907865 expect ( clientMock . getIdTokenClaims ) . toHaveBeenCalled ( ) ;
908866 expect ( claims ) . toStrictEqual ( {
909867 claim : '__test_claim__' ,
0 commit comments