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

Update to auth0-spa-js@1.19.3 #319

Merged
merged 4 commits into from
Jan 13, 2022
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
31 changes: 28 additions & 3 deletions __tests__/auth-provider.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useContext } from 'react';
import { mocked } from 'ts-jest/utils';
import Auth0Context from '../src/auth0-context';
import { renderHook, act } from '@testing-library/react-hooks';
import { Auth0Client } from '@auth0/auth0-spa-js';
import {
Auth0Client,
GetTokenSilentlyVerboseResponse,
} from '@auth0/auth0-spa-js';
import pkg from '../package.json';
import { createWrapper } from './helpers';

const clientMock = mocked(new Auth0Client({ client_id: '', domain: '' }));
const clientMock = jest.mocked(new Auth0Client({ client_id: '', domain: '' }));

describe('Auth0Provider', () => {
afterEach(() => {
Expand Down Expand Up @@ -414,6 +416,29 @@ describe('Auth0Provider', () => {
expect(clientMock.getTokenSilently).toHaveBeenCalled();
});

it('should get the full token response from getAccessTokenSilently when detailedResponse is true', async () => {
const tokenResponse: GetTokenSilentlyVerboseResponse = {
access_token: '123',
id_token: '456',
expires_in: 2,
};
(clientMock.getTokenSilently as jest.Mock).mockResolvedValue(tokenResponse);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const wrapper = createWrapper();
const { waitForNextUpdate, result } = renderHook(
() => useContext(Auth0Context),
{ wrapper }
);
await waitForNextUpdate();

await act(async () => {
const token = await result.current.getAccessTokenSilently({
detailedResponse: true,
});
expect(token).toBe(tokenResponse);
});
expect(clientMock.getTokenSilently).toHaveBeenCalled();
});

it('should normalize errors from getAccessTokenSilently method', async () => {
clientMock.getTokenSilently.mockRejectedValue(new ProgressEvent('error'));
const wrapper = createWrapper();
Expand Down
3 changes: 1 addition & 2 deletions __tests__/with-authentication-required.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import withAuthenticationRequired from '../src/with-authentication-required';
import { render, screen, waitFor } from '@testing-library/react';
import { Auth0Client, User } from '@auth0/auth0-spa-js';
import Auth0Provider from '../src/auth0-provider';
import { mocked } from 'ts-jest/utils';

const mockClient = mocked(new Auth0Client({ client_id: '', domain: '' }));
const mockClient = jest.mocked(new Auth0Client({ client_id: '', domain: '' }));

describe('withAuthenticationRequired', () => {
it('should block access to a private component when not authenticated', async () => {
Expand Down
1 change: 0 additions & 1 deletion examples/gatsby-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"gatsby-plugin-manifest": "^2.4.9",
"gatsby-plugin-offline": "^3.2.7",
"gatsby-plugin-react-helmet": "^3.3.2",
"gatsby-plugin-sharp": "^2.6.9",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed as this was not needed and had a downstream dependency that was failing the build imagemin/imagemin-mozjpeg#70

"gatsby-source-filesystem": "^2.3.8",
"gatsby-transformer-sharp": "^2.5.3",
"prop-types": "^15.7.2",
Expand Down
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ const pkg = require('./package.json');

module.exports = {
clearMocks: true,
coveragePathIgnorePatterns: ['/__tests__/'],
coveragePathIgnorePatterns: ['/__tests__/', 'index.tsx'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Istanbul isn't showing coverage for export only files at the moment gotwarlost/istanbul#930

coverageReporters: ['lcov', 'text', 'text-summary'],
preset: 'ts-jest',
reporters: [
'default',
['jest-junit', { outputDirectory: 'test-results/jest' }],
],
testEnvironment: 'jsdom',
testURL: 'https://www.example.com/',
testRegex: '/__tests__/.+test.tsx?$',
globals: {
Expand Down
Loading