Skip to content

Commit a21a3e4

Browse files
committed
Add default http mocks to the app context render test utility
1 parent e25a37f commit a21a3e4

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

x-pack/plugins/security_solution/public/common/mock/endpoint/app_context_render.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { PLUGIN_ID } from '../../../../../fleet/common';
2424
import { APP_ID } from '../../../../common/constants';
2525
import { KibanaContextProvider, KibanaServices } from '../../lib/kibana';
2626
import { MANAGEMENT_APP_ID } from '../../../management/common/constants';
27+
import { fleetGetPackageListHttpMock } from '../../../management/pages/endpoint_hosts/mocks';
2728

2829
type UiRender = (ui: React.ReactElement, options?: RenderOptions) => RenderResult;
2930

@@ -149,6 +150,9 @@ export const createAppRootMockRenderer = (): AppContextTestRender => {
149150
KibanaServices.init(globalKibanaServicesParams);
150151
}
151152

153+
// Some APIs need to be mocked right from the start because they are called as soon as the store is initialized
154+
applyDefaultCoreHttpMocks(coreStart.http);
155+
152156
return {
153157
store,
154158
history,
@@ -181,3 +185,10 @@ const createCoreStartMock = (): ReturnType<typeof coreMock.createStart> => {
181185

182186
return coreStart;
183187
};
188+
189+
const applyDefaultCoreHttpMocks = (http: AppContextTestRender['coreStart']['http']) => {
190+
// Need to mock getting the endpoint package from the fleet API because it is used as soon
191+
// as the store middleware for Endpoint list is initialized, thus mocking it here would avoid
192+
// unnecessary errors being output to the console
193+
fleetGetPackageListHttpMock(http, { ignoreUnMockedApiRouteErrors: true });
194+
};

0 commit comments

Comments
 (0)