-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Set up unit tests * Add junit reporter * Add test to CI * Ignore test helpers from coverage
- Loading branch information
1 parent
da7fbae
commit da68bd7
Showing
9 changed files
with
6,342 additions
and
654 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,3 +104,4 @@ dist | |
.tern-port | ||
|
||
.idea | ||
test-results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useContext } from 'react'; | ||
import { Auth0Context } from '../src/auth0-provider'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { Auth0Client } from '@auth0/auth0-spa-js'; | ||
import { createWrapper } from './helpers'; | ||
|
||
jest.mock('@auth0/auth0-spa-js'); | ||
|
||
describe('Auth0Provider', () => { | ||
it('should provide an instance of the Auth0Client', () => { | ||
const wrapper = createWrapper(); | ||
const { | ||
result: { current }, | ||
} = renderHook(() => useContext(Auth0Context), { wrapper }); | ||
expect(current).toBeInstanceOf(Auth0Client); | ||
}); | ||
|
||
it('should configure an instance of the Auth0Client', () => { | ||
const opts = { | ||
client_id: 'foo', | ||
domain: 'bar', | ||
}; | ||
const wrapper = createWrapper(opts); | ||
renderHook(() => useContext(Auth0Context), { | ||
wrapper, | ||
}); | ||
expect(Auth0Client).toHaveBeenCalledWith(opts); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Auth0ClientOptions } from '@auth0/auth0-spa-js'; | ||
import React, { PropsWithChildren } from 'react'; | ||
import Auth0Provider from '../src/auth0-provider'; | ||
|
||
export const createWrapper = ({ | ||
client_id = '__test_client_id__', | ||
domain = '__test_domain__', | ||
}: Partial<Auth0ClientOptions> = {}) => ({ | ||
children, | ||
}: PropsWithChildren<{}>) => ( | ||
<Auth0Provider domain={domain} client_id={client_id}> | ||
{children} | ||
</Auth0Provider> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import useAuth0 from '../src/use-auth0'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { Auth0Client } from '@auth0/auth0-spa-js'; | ||
import { createWrapper } from './helpers'; | ||
|
||
jest.mock('@auth0/auth0-spa-js'); | ||
|
||
describe('useAuth0', () => { | ||
it('should provide an instance of the Auth0Client', () => { | ||
const wrapper = createWrapper(); | ||
const { | ||
result: { current }, | ||
} = renderHook(useAuth0, { wrapper }); | ||
expect(current).toBeInstanceOf(Auth0Client); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
clearMocks: true, | ||
coveragePathIgnorePatterns: ['/__tests__/'], | ||
coverageReporters: ['lcov', 'text', 'text-summary'], | ||
preset: 'ts-jest', | ||
reporters: [ | ||
'default', | ||
['jest-junit', { outputDirectory: 'test-results/jest' }] | ||
], | ||
testRegex: '/__tests__/.+test\.tsx?$' | ||
}; |
Oops, something went wrong.