Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] [React18] Migrate test suites to account for testing library upgrades observability-ui (#201173) #201322

Merged
merged 1 commit into from
Nov 22, 2024
Merged
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
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