|
12 | 12 |
|
13 | 13 | import * as React from 'react'; |
14 | 14 | import { mount } from 'enzyme'; |
| 15 | +import { act } from 'react-dom/test-utils'; |
15 | 16 | import LoginCallback from '../../src/LoginCallback'; |
16 | 17 | import Security from '../../src/Security'; |
17 | 18 |
|
@@ -138,16 +139,44 @@ describe('<LoginCallback />', () => { |
138 | 139 | expect(wrapper.text()).toBe(''); // no output since we expect to be redirected |
139 | 140 | }); |
140 | 141 |
|
141 | | - it('will treat isInteractionRequired like a normal error if not onAuthResume is passed', () => { |
142 | | - oktaAuth.isInteractionRequired = jest.fn().mockImplementation( () => true ); |
| 142 | + it('renders errors caught from handleLoginRedirect', async () => { |
| 143 | + const errorMsg = 'error on callback'; |
| 144 | + authState.isPending = true; |
| 145 | + authState.isAuthenticated = false; |
| 146 | + oktaAuth.handleLoginRedirect.mockImplementation(() => { |
| 147 | + return Promise.reject(new Error(errorMsg)); |
| 148 | + }); |
143 | 149 | const wrapper = mount( |
144 | 150 | <Security {...mockProps}> |
145 | 151 | <LoginCallback /> |
146 | 152 | </Security> |
147 | 153 | ); |
148 | | - expect(wrapper.text()).toBe(''); // TODO: should be noticed as an error OKTA-361608 |
| 154 | + return await act(async () => { |
| 155 | + await wrapper.update(); // set state |
| 156 | + await wrapper.update(); // render error |
| 157 | + expect(wrapper.text()).toBe('Error: ' + errorMsg); |
| 158 | + }); |
149 | 159 | }); |
150 | 160 |
|
| 161 | + it('will treat isInteractionRequired like a normal error if not onAuthResume is passed', async () => { |
| 162 | + oktaAuth.isInteractionRequired = jest.fn().mockImplementation( () => true ); |
| 163 | + const errorMsg = 'error on callback'; |
| 164 | + authState.isPending = true; |
| 165 | + authState.isAuthenticated = false; |
| 166 | + oktaAuth.handleLoginRedirect.mockImplementation(() => { |
| 167 | + return Promise.reject(new Error(errorMsg)); |
| 168 | + }); |
| 169 | + const wrapper = mount( |
| 170 | + <Security {...mockProps}> |
| 171 | + <LoginCallback /> |
| 172 | + </Security> |
| 173 | + ); |
| 174 | + return await act(async () => { |
| 175 | + await wrapper.update(); // set state |
| 176 | + await wrapper.update(); // render error |
| 177 | + expect(wrapper.text()).toBe('Error: ' + errorMsg); |
| 178 | + }); |
| 179 | + }); |
151 | 180 | }); |
152 | 181 |
|
153 | 182 | }); |
0 commit comments