Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 26c65ed

Browse files
committed
refactor: clean up setup code and revise comments
1 parent 44801af commit 26c65ed

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

plugins/backstage-plugin-coder/src/components/CoderProvider/CoderAuthProvider.test.tsx

+12-10
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
* @todo 2024-05-23 - Right now, there is a conflict when you try to call
1010
* Backstage's wrapInTestApp and also try to mock out localStorage. They
1111
* 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.
1416
*
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.
1820
*/
1921
import React, { type ReactNode } from 'react';
2022
import { render, screen, waitFor, within } from '@testing-library/react';
@@ -43,12 +45,12 @@ import { CoderAppConfigProvider } from './CoderAppConfigProvider';
4345
afterEach(() => {
4446
jest.restoreAllMocks();
4547

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());
4850
window.localStorage.removeItem(TOKEN_STORAGE_KEY);
4951
});
5052

51-
function renderAuthProvider(children: ReactNode) {
53+
function renderAuthProvider(children?: ReactNode) {
5254
const urlSync = new UrlSync({
5355
apis: {
5456
configApi: getMockConfigApi(),
@@ -135,7 +137,7 @@ describe(`${CoderAuthProvider.name}`, () => {
135137
});
136138

137139
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();
139141
const authFallbackTrigger = await screen.findByRole('button', {
140142
name: fallbackTriggerMatcher,
141143
});
@@ -162,7 +164,7 @@ describe(`${CoderAuthProvider.name}`, () => {
162164
});
163165

164166
it('Lets the user go through a full authentication flow via the fallback auth UI', async () => {
165-
renderAuthProvider(<></>);
167+
renderAuthProvider();
166168
const user = userEvent.setup();
167169

168170
const authFallbackTrigger = await screen.findByRole('button', {

0 commit comments

Comments
 (0)