From 051ad6d180acb3551486d0d1f30cb38f48cf2171 Mon Sep 17 00:00:00 2001 From: Steve Hobbs Date: Thu, 11 Jul 2019 17:28:47 +0100 Subject: [PATCH] Made options argument for popup and redirect optional (#61) * Made options argument for popup and redirect optional * Added no arguments test for loginWithPopup --- __tests__/index.test.ts | 15 +++++++++++++++ src/Auth0Client.ts | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index d781d0645..88fd92026 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -246,6 +246,12 @@ describe('Auth0', () => { { daysUntilExpire: 1 } ); }); + it('can be called with no arguments', async () => { + const { auth0, utils } = await setup(); + + await auth0.loginWithPopup(); + expect(utils.openPopup).toHaveBeenCalled(); + }); }); describe('loginWithRedirect()', () => { const REDIRECT_OPTIONS = { @@ -347,6 +353,15 @@ describe('Auth0', () => { `https://test.auth0.com/authorize?query=params${TEST_TELEMETRY_QUERY_STRING}` ); }); + it('can be called with no arguments', async () => { + const { auth0 } = await setup(); + + await auth0.loginWithRedirect(); + + expect(window.location.assign).toHaveBeenCalledWith( + `https://test.auth0.com/authorize?query=params${TEST_TELEMETRY_QUERY_STRING}` + ); + }); }); describe('handleRedirectCallback()', () => { it('throws when there is no query string', async () => { diff --git a/src/Auth0Client.ts b/src/Auth0Client.ts index 06944ccc0..891c38796 100644 --- a/src/Auth0Client.ts +++ b/src/Auth0Client.ts @@ -98,7 +98,7 @@ export default class Auth0Client { * * @param options */ - public async loginWithPopup(options: PopupLoginOptions) { + public async loginWithPopup(options: PopupLoginOptions = {}) { const popup = await openPopup(); const { ...authorizeOptions } = options; const stateIn = encodeState(createRandomString()); @@ -191,7 +191,7 @@ export default class Auth0Client { * * @param options */ - public async loginWithRedirect(options: RedirectLoginOptions) { + public async loginWithRedirect(options: RedirectLoginOptions = {}) { const { redirect_uri, appState, ...authorizeOptions } = options; const stateIn = encodeState(createRandomString()); const nonceIn = createRandomString();