Created
November 24, 2020 15:21
-
-
Save mraible/e304df9cdcc93ed3e42eb8b903391d79 to your computer and use it in GitHub Desktop.
App.test.js from CRA with Okta React 4.0.0
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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { act } from 'react-dom/test-utils'; | |
import App from './App'; | |
jest.mock('@okta/okta-auth-js', () => { | |
return { | |
OktaAuth: jest.fn(() => { | |
return { | |
userAgent: 'okta/okta-auth-js', | |
options: {}, | |
authStateManager: { | |
getAuthState: jest.fn().mockImplementation(() => | |
({ | |
isPending: true, | |
isAuthenticated: false, | |
idToken: null, | |
accessToken: null, | |
refreshToken: null | |
})), | |
subscribe: jest.fn(), | |
updateAuthState: jest.fn(), | |
}, | |
isLoginRedirect: jest.fn().mockImplementation(() => false), | |
} | |
}) | |
} | |
}); | |
/*jest.mock('@okta/okta-react', () => { | |
return { | |
withOktaAuth: jest.fn(), | |
Security: ({ children }) => (<>{children}</>) | |
} | |
});*/ | |
let container; | |
beforeEach(() => { | |
container = document.createElement('div'); | |
document.body.appendChild(container); | |
}); | |
afterEach(() => { | |
document.body.removeChild(container); | |
container = null; | |
}); | |
test('renders learn react link', async () => { | |
await act(async () => { | |
ReactDOM.render(<App/>, container); | |
}); | |
const linkElement = container.querySelector('a'); | |
expect(linkElement.textContent).toBe('Learn React'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment