Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-1125] createAuth0Client now throws errors that are not login_required #369

Merged
merged 1 commit into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,64 @@ describe('Auth0', () => {
domain: TEST_DOMAIN,
client_id: TEST_CLIENT_ID
});

expect(auth0).toBeInstanceOf(Auth0Client);
});

it('should call `utils.validateCrypto`', async () => {
const { utils } = await setup();

expect(utils.validateCrypto).toHaveBeenCalled();
});

it('should absorb "login_required" errors', async () => {
const { utils, storage } = await setup();

utils.runIframe.mockImplementation(() => {
throw {
error: 'login_required',
error_message: 'Login required'
};
});

storage.get.mockReturnValue(true);

const auth0 = await createAuth0Client({
domain: TEST_DOMAIN,
client_id: TEST_CLIENT_ID
});

expect(auth0).toBeInstanceOf(Auth0Client);
expect(utils.runIframe).toHaveBeenCalled();
});

it('should throw other errors that are not "login_required"', async () => {
const { utils, storage } = await setup();

utils.runIframe.mockImplementation(() => {
throw {
error: 'some_other_error',
error_message: 'This is a different error to login_required'
};
});

storage.get.mockReturnValue(true);

// We expect one assertion, meaning that if the function under test
// does not throw, it will still fail the test.
expect.assertions(1);

try {
await createAuth0Client({
domain: TEST_DOMAIN,
client_id: TEST_CLIENT_ID
});
} catch (e) {
expect(e.error).toEqual('some_other_error');
}
});
});

describe('loginWithPopup()', () => {
it('opens popup', async () => {
const { auth0, utils } = await setup();
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export default async function createAuth0Client(options: Auth0ClientOptions) {
ignoreCache: true
});
} catch (error) {
// ignore
if (error.error !== 'login_required') {
throw error;
}
}
return auth0;
}