Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/login-web-app/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import '@testing-library/jest-dom/vitest';
import { vi } from 'vitest';

// bootstrap-configuration.ts throws at import time if window.__CONFIG__ is unset.
// @ts-expect-error window.__CONFIG__ is not declared on the Window type
window.__CONFIG__ = {
initialUrl: 'https://example.test/auth',
haapi: {
clientId: 'test-client',
tokenEndpoint: 'https://example.test/oauth/token',
},
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the need come up because of other test files?

// jsdom doesn't implement <dialog> — minimal mocks for open/close state.
HTMLDialogElement.prototype.show = vi.fn(function mock(this: HTMLDialogElement) {
this.open = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { act } from 'react';
import { useHaapiStepper } from './HaapiStepperHook';
import type { HaapiStepperHistoryEntry, HaapiStepperNextStepAction } from './haapi-stepper.types';
import { HaapiStepperActionStep, HaapiStepperFormAction } from './haapi-stepper.types';
import type { BootstrapConfiguration } from '../../data-access/bootstrap-configuration';
import { configuration } from '../../data-access/bootstrap-configuration';

describe('HaapiStepper', () => {
const initialStepType = HAAPI_STEPS.AUTHENTICATION;
Expand All @@ -53,7 +53,7 @@ describe('HaapiStepper', () => {
</HaapiStepper>
);

expect(mockHaapiFetch).toHaveBeenCalledWith(mockConfiguration.initialUrl, { method: 'GET' });
expect(mockHaapiFetch).toHaveBeenCalledWith(configuration.initialUrl, { method: 'GET' });

const stepRendered = await screen.findByTestId('step-type');

Expand Down Expand Up @@ -714,17 +714,6 @@ vi.mock('../../data-access/haapi-fetch-initializer', () => {
};
});

const mockConfiguration: Partial<BootstrapConfiguration> = vi.hoisted(() => {
return {
initialUrl: 'https://example.com/auth',
};
});
vi.mock('../../data-access/bootstrap-configuration', () => {
return {
configuration: mockConfiguration,
};
});

const mockThrowErrorToAppErrorBoundary = vi.fn();
vi.mock('../../util/useThrowErrorToAppErrorBoundary', () => ({
// eslint-disable-next-line @eslint-react/hooks-extra/no-unnecessary-use-prefix
Expand Down
Loading