fix: Fix tests broken by @backstage/core-components update
Signed-off-by: Carlos Esteban Lopez <lcarlosesteb@vmware.com>
This commit is contained in:
committed by
Carlos Lopez
parent
830687539f
commit
1326691934
@@ -23,6 +23,7 @@ import { FetchApi } from '@backstage/core-plugin-api';
|
||||
import { IdentityApi } from '@backstage/core-plugin-api';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { JsonValue } from '@backstage/types';
|
||||
import { MatcherFunction } from '@testing-library/react';
|
||||
import { Observable } from '@backstage/types';
|
||||
import { PermissionApi } from '@backstage/plugin-permission-react';
|
||||
import { PropsWithChildren } from 'react';
|
||||
@@ -241,6 +242,9 @@ export type TestAppOptions = {
|
||||
};
|
||||
};
|
||||
|
||||
// @public
|
||||
export const textContentMatcher: (text: string) => MatcherFunction;
|
||||
|
||||
// @public
|
||||
export function withLogCollector(
|
||||
callback: AsyncLogCollector,
|
||||
|
||||
@@ -29,7 +29,7 @@ import {
|
||||
attachComponentData,
|
||||
createRouteRef,
|
||||
} from '@backstage/core-plugin-api';
|
||||
import { RenderResult } from '@testing-library/react';
|
||||
import { MatcherFunction, RenderResult } from '@testing-library/react';
|
||||
import { renderWithEffects } from './testingLibrary';
|
||||
import { defaultApis } from './defaultApis';
|
||||
import { mockApis } from './mockApis';
|
||||
@@ -242,3 +242,24 @@ export async function renderInTestApp(
|
||||
wrapper: createTestAppWrapper(options),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a `@testing-library/react` valid MatcherFunction for supplied text
|
||||
*
|
||||
* @param string - text Text to match by element's textContent
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const textContentMatcher =
|
||||
(text: string): MatcherFunction =>
|
||||
(_, node) => {
|
||||
if (!node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const hasText = (textNode: Element) => textNode?.textContent === text;
|
||||
const childrenDontHaveText = (containerNode: Element) =>
|
||||
Array.from(containerNode?.children).every(child => !hasText(child));
|
||||
|
||||
return hasText(node) && childrenDontHaveText(node);
|
||||
};
|
||||
|
||||
@@ -19,6 +19,7 @@ export { default as mockBreakpoint } from './mockBreakpoint';
|
||||
export {
|
||||
wrapInTestApp,
|
||||
renderInTestApp,
|
||||
textContentMatcher,
|
||||
createTestAppWrapper,
|
||||
} from './appWrappers';
|
||||
export type { TestAppOptions } from './appWrappers';
|
||||
|
||||
Reference in New Issue
Block a user