Skip to content

Commit

Permalink
Fixed failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Oct 19, 2023
1 parent 16faf05 commit 8b19a33
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/app-utils/src/components/AppBootstrap.test.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand All @@ -33,6 +45,7 @@ jest.mock('@deephaven/jsapi-components', () => ({

const mockChildText = 'Mock Child';
const mockChild = <div>{mockChildText}</div>;
const mockPluginModuleMapEmpty: PluginModuleMap = new Map();

function expectMockChild() {
return expect(screen.queryByText(mockChildText));
Expand Down Expand Up @@ -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(
<AppBootstrap serverUrl={API_URL} pluginsUrl={PLUGINS_URL}>
Expand Down

0 comments on commit 8b19a33

Please sign in to comment.