fix: remove test has no assertions warning

Signed-off-by: Paul Schultz <pschultz@pobox.com>
This commit is contained in:
Paul Schultz
2024-12-11 14:26:46 -06:00
parent a65f2d5714
commit d14b4a77c5
8 changed files with 46 additions and 29 deletions
@@ -55,7 +55,9 @@ describe('ApiProvider', () => {
<MyHocConsumer />
</ApiProvider>,
);
renderedHoc.getByText('hoc message: hello');
expect(renderedHoc.getByText('hoc message: hello').innerHTML).toEqual(
'hoc message: hello',
);
});
it('should provide nested access to apis', () => {
@@ -84,7 +86,7 @@ describe('ApiProvider', () => {
</ApiProvider>
</ApiProvider>,
);
renderedHook.getByText('a=z b=y');
expect(renderedHook.getByText('a=z b=y').innerHTML).toEqual('a=z b=y');
});
it('should ignore deps in prototype', () => {
@@ -107,7 +109,9 @@ describe('ApiProvider', () => {
<MyWeirdHocConsumer />
</ApiProvider>,
);
renderedHoc.getByText('hoc message: hello');
expect(renderedHoc.getByText('hoc message: hello').innerHTML).toEqual(
'hoc message: hello',
);
});
it('should error if no provider is available', () => {
@@ -229,6 +233,8 @@ describe('v1 consumer', () => {
<MyHookConsumerV1 />
</ApiProvider>,
);
renderedHook.getByText('hook message: hello');
expect(renderedHook.getByText('hook message: hello').innerHTML).toEqual(
'hook message: hello',
);
});
});
@@ -34,7 +34,9 @@ describe('<CodeSnippet />', () => {
// react-syntax-highlighter is large and can cause significant slowdowns
// This test makes sure we're loading things in asynchronously and not too broadly.
it('renders quickly', async () => {
await renderInTestApp(<CodeSnippet text="" language="javascript" />);
await expect(
renderInTestApp(<CodeSnippet text="" language="javascript" />),
).resolves.not.toThrow();
}, 1000);
it('renders text without exploding', async () => {
@@ -58,8 +58,8 @@ describe('<FeatureCalloutCircular />', () => {
description="description"
/>,
);
rendered.getByText('description');
rendered.getByText('title');
expect(rendered.getByText('description')).toBeInTheDocument();
expect(rendered.getByText('title')).toBeInTheDocument();
});
it('renders with correct style', async () => {
@@ -20,10 +20,12 @@ import { OverflowTooltip } from './OverflowTooltip';
describe('<OverflowTooltip />', () => {
it('renders without exploding', async () => {
render(<OverflowTooltip text="Text that may overflow" />);
expect(
render(<OverflowTooltip text="Text that may overflow" />),
).toBeTruthy();
});
it('renders without exploding when the text prop is missing', async () => {
render(<OverflowTooltip text={undefined} />);
expect(render(<OverflowTooltip text={undefined} />)).toBeTruthy();
});
});
@@ -24,34 +24,34 @@ describe('<Gauge />', () => {
const { getByText } = await renderInTestApp(
<Gauge value={10} fractional={false} />,
);
getByText('10%');
expect(getByText('10%')).toBeInTheDocument();
});
it('handles fractional prop', async () => {
const { getByText } = await renderInTestApp(
<Gauge value={0.1} fractional />,
);
getByText('10%');
expect(getByText('10%')).toBeInTheDocument();
});
it('handles max prop', async () => {
const { getByText } = await renderInTestApp(
<Gauge value={1} max={10} fractional={false} />,
);
getByText('1%');
expect(getByText('1%')).toBeInTheDocument();
});
it('handles unit prop', async () => {
const { getByText } = await renderInTestApp(
<Gauge value={10} fractional={false} unit="m" />,
);
getByText('10m');
expect(getByText('10m')).toBeInTheDocument();
});
it('handle relativeToMax prop', async () => {
const { getByText } = await renderInTestApp(
<Gauge value={7} max={10} relativeToMax fractional={false} unit=" pts" />,
);
getByText('7 pts');
expect(getByText('7 pts')).toBeInTheDocument();
});
it('handle decimalDigits prop', async () => {
@@ -65,7 +65,7 @@ describe('<Gauge />', () => {
unit="/10"
/>,
);
getByText('5.50/10');
expect(getByText('5.50/10')).toBeInTheDocument();
});
const ok = '#111';
@@ -17,6 +17,7 @@
import React from 'react';
import { ContentHeader } from './ContentHeader';
import { renderInTestApp } from '@backstage/test-utils';
import _ from 'lodash';
jest.mock('react-helmet', () => {
return {
@@ -27,14 +28,14 @@ jest.mock('react-helmet', () => {
describe('<ContentHeader/>', () => {
it('should render with title', async () => {
const rendered = await renderInTestApp(<ContentHeader title="Title" />);
rendered.getByText('Title');
expect(rendered.getByText('Title')).toBeInTheDocument();
});
it('should render without title', async () => {
const rendered = await renderInTestApp(
<ContentHeader>content</ContentHeader>,
);
rendered.getByText('content');
expect(rendered.getByText('content')).toBeInTheDocument();
});
it('should render with titleComponent', async () => {
@@ -43,13 +44,13 @@ describe('<ContentHeader/>', () => {
const rendered = await renderInTestApp(
<ContentHeader titleComponent={titleComponent} />,
);
rendered.getByText(title);
expect(rendered.getByText(title)).toBeInTheDocument();
});
it('should render with description', async () => {
const rendered = await renderInTestApp(
<ContentHeader description="description" />,
);
rendered.getByText('description');
expect(rendered.getByText('description')).toBeInTheDocument();
});
});
@@ -29,42 +29,46 @@ jest.mock('react-helmet', () => {
describe('<Header/>', () => {
it('should render with title', async () => {
const rendered = await renderInTestApp(<Header title="Title" />);
rendered.getByText('Title');
expect(rendered.getByText('Title')).toBeInTheDocument();
});
it('should set document title', async () => {
const rendered = await renderInTestApp(<Header title="Title1" />);
rendered.getByText('Title1');
rendered.getByText('defaultTitle: Title1 | Backstage');
expect(rendered.getByText('Title1')).toBeInTheDocument();
expect(
rendered.getByText('defaultTitle: Title1 | Backstage'),
).toBeInTheDocument();
});
it('should override document title', async () => {
const rendered = await renderInTestApp(
<Header title="Title1" pageTitleOverride="Title2" />,
);
rendered.getByText('Title1');
rendered.getByText('defaultTitle: Title2 | Backstage');
expect(rendered.getByText('Title1')).toBeInTheDocument();
expect(
rendered.getByText('defaultTitle: Title2 | Backstage'),
).toBeInTheDocument();
});
it('should have subtitle', async () => {
const rendered = await renderInTestApp(
<Header title="Title" subtitle="Subtitle" />,
);
rendered.getByText('Subtitle');
expect(rendered.getByText('Subtitle')).toBeInTheDocument();
});
it('should have type rendered', async () => {
const rendered = await renderInTestApp(
<Header title="Title" type="tool" />,
);
rendered.getByText('tool');
expect(rendered.getByText('tool')).toBeInTheDocument();
});
it('should have breadcrumb rendered', async () => {
const rendered = await renderInTestApp(
<Header title="Title" type="tool" typeLink="/tool" />,
);
rendered.getAllByText('Title');
expect(rendered.getAllByText('Title')).toBeTruthy();
});
it('should use app.title', async () => {
@@ -75,6 +79,6 @@ describe('<Header/>', () => {
<Header title="Title" type="tool" typeLink="/tool" />,
</TestApiProvider>,
);
rendered.getAllByText(/Title | Blah/);
expect(rendered.getAllByText(/Title | Blah/)).toBeTruthy();
});
});
@@ -22,7 +22,9 @@ import userEvent from '@testing-library/user-event';
describe('<ComponentContextMenu />', () => {
it('renders without any items and without exploding', async () => {
await renderInTestApp(<HeaderActionMenu actionItems={[]} />);
await expect(
renderInTestApp(<HeaderActionMenu actionItems={[]} />),
).resolves.not.toThrow();
});
it('can open the menu and click menu items', async () => {