From 8b19a333743ea9d03e24af402ce9be924334769b Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Thu, 19 Oct 2023 12:52:46 -0500 Subject: [PATCH] Fixed failing test #1543 --- .../src/components/AppBootstrap.test.tsx | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/app-utils/src/components/AppBootstrap.test.tsx b/packages/app-utils/src/components/AppBootstrap.test.tsx index 84a474a42d..dc838d24b7 100644 --- a/packages/app-utils/src/components/AppBootstrap.test.tsx +++ b/packages/app-utils/src/components/AppBootstrap.test.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useContext } from 'react'; import { AUTH_HANDLER_TYPE_ANONYMOUS } from '@deephaven/auth-plugins'; import { ApiContext } from '@deephaven/jsapi-bootstrap'; import { BROADCAST_LOGIN_MESSAGE } from '@deephaven/jsapi-utils'; @@ -10,6 +10,18 @@ import type { import { TestUtils } from '@deephaven/utils'; import { act, render, screen } from '@testing-library/react'; import AppBootstrap from './AppBootstrap'; +import { PluginsContext } from './PluginsBootstrap'; +import { PluginModuleMap } from '../plugins'; + +const { asMock } = TestUtils; + +jest.mock('react', () => { + const actual = jest.requireActual('react'); + return { + ...actual, + useContext: jest.fn(actual.useContext), + }; +}); const API_URL = 'http://mockserver.net:8111'; const PLUGINS_URL = 'http://mockserver.net:8111/plugins'; @@ -33,6 +45,7 @@ jest.mock('@deephaven/jsapi-components', () => ({ const mockChildText = 'Mock Child'; const mockChild =
{mockChildText}
; +const mockPluginModuleMapEmpty: PluginModuleMap = new Map(); function expectMockChild() { return expect(screen.queryByText(mockChildText)); @@ -60,6 +73,17 @@ beforeEach(() => { it('should throw if api has not been bootstrapped', () => { TestUtils.disableConsoleOutput(); + asMock(useContext).mockImplementation(context => { + // ThemeBootstrap doesn't render children until plugins are loaded. We need + // a non-null PluginsContext value to render the children and get the expected + // missing api error. + if (context === PluginsContext) { + return mockPluginModuleMapEmpty; + } + + return jest.requireActual('react').useContext(context); + }); + expect(() => render(