Skip to content

Commit

Permalink
[React18] Migrated test suites to accommodate changes to testing libr…
Browse files Browse the repository at this point in the history
…ary owned by observability-ui
  • Loading branch information
eokoneyo committed Nov 21, 2024
1 parent 51a84eb commit 76bb55c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import React, { ReactNode } from 'react';
import { renderHook } from '@testing-library/react';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { CoreStart } from '@kbn/core/public';
import { createKibanaReactContext } from '@kbn/kibana-react-plugin/public';
Expand All @@ -28,7 +28,7 @@ const kibanaServices = {
} as unknown as Partial<CoreStart>;
const KibanaContext = createKibanaReactContext(kibanaServices);

function Wrapper({ children }: { children?: ReactNode }) {
function Wrapper({ children }: React.PropsWithChildren) {
return (
<MemoryRouter>
<KibanaContext.Provider>{children}</KibanaContext.Provider>
Expand All @@ -38,18 +38,20 @@ function Wrapper({ children }: { children?: ReactNode }) {

describe('useBreadcrumbs', () => {
afterEach(() => {
setBreadcrumbs.mockClear();
setTitle.mockClear();
jest.clearAllMocks();
});

describe('when setBreadcrumbs and setTitle are not defined', () => {
it('does not set breadcrumbs or the title', () => {
renderHook(() => useBreadcrumbs([]), {
wrapper: ({ children }: React.PropsWithChildren<{}>) => (
wrapper: ({ children }: React.PropsWithChildren) => (
<MemoryRouter>
<KibanaContext.Provider
services={
{ ...kibanaServices, chrome: { docTitle: {} } } as unknown as Partial<CoreStart>
{
...kibanaServices,
chrome: { ...kibanaServices.chrome, docTitle: {}, setBreadcrumbs: null },
} as unknown as Partial<CoreStart>
}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const useBreadcrumbs = (
const setBreadcrumbs = useMemo(() => {
if (!serverless?.setBreadcrumbs) {
return (breadcrumbs: ChromeBreadcrumb[]) =>
chromeSetBreadcrumbs(
chromeSetBreadcrumbs?.(
breadcrumbs,
!classicOnly
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import React, { PropsWithChildren } from 'react';
import { Router } from '@kbn/shared-ux-router';
Expand Down

0 comments on commit 76bb55c

Please sign in to comment.