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

[React18] Migrate test suites to account for testing library upgrades observability-ui #201173

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?.(
Copy link
Contributor Author

@eokoneyo eokoneyo Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this is because without this the usage of the function doesn't match what we are actually testing, see https://github.com/elastic/kibana/pull/196785/files#diff-42926237891e15e7b4f739835e1f1840aac8c7206d36b0b6680b221949be4ebeL62-L65 prior to the PR that's linked, setBreadCrumbs could have been a null value, and could have accommodations made for it when using it, but now it's always defined but at the same the invoked function still could be undefined.

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