9
9
* @todo 2024-05-23 - Right now, there is a conflict when you try to call
10
10
* Backstage's wrapInTestApp and also try to mock out localStorage. They
11
11
* interact in such a way that when you call your mock's getItem method, it
12
- * immediately throws an error with an error message that is so obscure that
13
- * there are no Google results for it.
12
+ * immediately throws an error. Didn't want to get rid of wrapInTestApp, because
13
+ * then that would require removing official Backstage components. wrapInTestApp
14
+ * sets up a lot of things behind the scenes like React Router that these
15
+ * components rely on.
14
16
*
15
- * Figured out a way to write the tests in a way that didn't involve extra
16
- * mocking, but it's not as airtight as it could be. Definitely worth opening an
17
- * issue with the Backstage repo upstream.
17
+ * Figured out a way to write the tests that didn't involve extra mocking, but
18
+ * it's not as airtight as it could be. Definitely worth opening an issue with
19
+ * the Backstage repo upstream.
18
20
*/
19
21
import React , { type ReactNode } from 'react' ;
20
22
import { render , screen , waitFor , within } from '@testing-library/react' ;
@@ -43,12 +45,12 @@ import { CoderAppConfigProvider } from './CoderAppConfigProvider';
43
45
afterEach ( ( ) => {
44
46
jest . restoreAllMocks ( ) ;
45
47
46
- const wrapperNode = document . querySelector ( BACKSTAGE_APP_ROOT_ID ) ;
47
- wrapperNode ?. remove ( ) ;
48
+ const appRootNodes = document . querySelectorAll ( BACKSTAGE_APP_ROOT_ID ) ;
49
+ appRootNodes . forEach ( node => node . remove ( ) ) ;
48
50
window . localStorage . removeItem ( TOKEN_STORAGE_KEY ) ;
49
51
} ) ;
50
52
51
- function renderAuthProvider ( children : ReactNode ) {
53
+ function renderAuthProvider ( children ? : ReactNode ) {
52
54
const urlSync = new UrlSync ( {
53
55
apis : {
54
56
configApi : getMockConfigApi ( ) ,
@@ -135,7 +137,7 @@ describe(`${CoderAuthProvider.name}`, () => {
135
137
} ) ;
136
138
137
139
it ( 'Will display an auth fallback input when there are no Coder components to be tracked and does not consider users of' , async ( ) => {
138
- renderAuthProvider ( < > </ > ) ;
140
+ renderAuthProvider ( ) ;
139
141
const authFallbackTrigger = await screen . findByRole ( 'button' , {
140
142
name : fallbackTriggerMatcher ,
141
143
} ) ;
@@ -162,7 +164,7 @@ describe(`${CoderAuthProvider.name}`, () => {
162
164
} ) ;
163
165
164
166
it ( 'Lets the user go through a full authentication flow via the fallback auth UI' , async ( ) => {
165
- renderAuthProvider ( < > </ > ) ;
167
+ renderAuthProvider ( ) ;
166
168
const user = userEvent . setup ( ) ;
167
169
168
170
const authFallbackTrigger = await screen . findByRole ( 'button' , {
0 commit comments