-
Notifications
You must be signed in to change notification settings - Fork 250
/
ssr.test.tsx
30 lines (28 loc) · 932 Bytes
/
ssr.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* @jest-environment node
*/
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import { Auth0Provider, Auth0Context } from '../src';
jest.unmock('@auth0/auth0-spa-js');
describe('In a Node SSR environment', () => {
it('auth state is initialised', async () => {
let isLoading, isAuthenticated, user, loginWithRedirect;
ReactDOMServer.renderToString(
<Auth0Provider clientId="__client_id__" domain="__domain__">
<Auth0Context.Consumer>
{(value): JSX.Element => {
({ isLoading, isAuthenticated, user, loginWithRedirect } = value);
return <div>App</div>;
}}
</Auth0Context.Consumer>
</Auth0Provider>
);
expect(isLoading).toBeTruthy();
expect(isAuthenticated).toBeFalsy();
expect(user).toBeUndefined();
await expect(loginWithRedirect).rejects.toThrowError(
'window is not defined'
);
});
});