diff --git a/packages/react/src/ActionList/Group.test.tsx b/packages/react/src/ActionList/Group.test.tsx
index 7d282da6296..223ac72e80d 100644
--- a/packages/react/src/ActionList/Group.test.tsx
+++ b/packages/react/src/ActionList/Group.test.tsx
@@ -5,7 +5,7 @@ import BaseStyles from '../BaseStyles'
import {ActionList} from '.'
import {ActionMenu} from '..'
import {FeatureFlags} from '../FeatureFlags'
-import {implementsClassName} from '../utils/testing'
+import {implementsClassName, withExpectedConsoleError} from '../utils/testing'
import classes from './Group.module.css'
describe('ActionList.Group', () => {
@@ -22,24 +22,26 @@ describe('ActionList.Group', () => {
implementsClassName(ActionList.GroupHeading, classes.GroupHeading)
it('should throw an error when ActionList.GroupHeading has an `as` prop when it is used within ActionMenu context', async () => {
- expect(() =>
- HTMLRender(
-
-
- Trigger
-
-
-
- Group Heading
-
-
-
-
- ,
- ),
- ).toThrow(
- "Looks like you are trying to set a heading level to a menu role. Group headings for menu type action lists are for representational purposes, and rendered as divs. Therefore they don't need a heading level.",
- )
+ withExpectedConsoleError(() => {
+ expect(() =>
+ HTMLRender(
+
+
+ Trigger
+
+
+
+ Group Heading
+
+
+
+
+ ,
+ ),
+ ).toThrow(
+ "Looks like you are trying to set a heading level to a menu role. Group headings for menu type action lists are for representational purposes, and rendered as divs. Therefore they don't need a heading level.",
+ )
+ })
})
it('should render the ActionList.GroupHeading component as a heading with the given heading level', async () => {
@@ -56,19 +58,21 @@ describe('ActionList.Group', () => {
expect(heading).toHaveTextContent('Group Heading')
})
it('should throw an error if ActionList.GroupHeading is used without an `as` prop when no role is specified (for list role)', async () => {
- expect(() =>
- HTMLRender(
-
- Heading
-
- Group Heading
- Item
-
- ,
- ),
- ).toThrow(
- "You are setting a heading for a list, that requires a heading level. Please use 'as' prop to set a proper heading level.",
- )
+ withExpectedConsoleError(() => {
+ expect(() =>
+ HTMLRender(
+
+ Heading
+
+ Group Heading
+ Item
+
+ ,
+ ),
+ ).toThrow(
+ "You are setting a heading for a list, that requires a heading level. Please use 'as' prop to set a proper heading level.",
+ )
+ })
})
it('should render the ActionList.GroupHeading component as a span (not a heading tag) when role is specified as listbox', async () => {
const container = HTMLRender(
@@ -191,44 +195,48 @@ describe('ActionList.Group', () => {
})
it('throws when GroupHeading.TrailingAction is used inside an ActionMenu (menu role) and the feature flag is enabled', () => {
- expect(() =>
- HTMLRender(
-
-
-
- Trigger
-
-
-
-
- Group Heading
-
-
-
-
-
-
-
- ,
- ),
- ).toThrow(/can not be used inside an ActionList with an ARIA role of "menu"/)
+ withExpectedConsoleError(() => {
+ expect(() =>
+ HTMLRender(
+
+
+
+ Trigger
+
+
+
+
+ Group Heading
+
+
+
+
+
+
+
+ ,
+ ),
+ ).toThrow(/can not be used inside an ActionList with an ARIA role of "menu"/)
+ })
})
it('throws when GroupHeading.TrailingAction is used inside a listbox role and the feature flag is enabled', () => {
- expect(() =>
- HTMLRender(
-
-
-
-
- Group Heading
-
-
-
-
- ,
- ),
- ).toThrow(/can not be used inside an ActionList with an ARIA role of "listbox"/)
+ withExpectedConsoleError(() => {
+ expect(() =>
+ HTMLRender(
+
+
+
+
+ Group Heading
+
+
+
+
+ ,
+ ),
+ ).toThrow(/can not be used inside an ActionList with an ARIA role of "listbox"/)
+ })
})
})
})
diff --git a/packages/react/src/ActionList/Heading.test.tsx b/packages/react/src/ActionList/Heading.test.tsx
index 316d4bad06d..6405d29f93e 100644
--- a/packages/react/src/ActionList/Heading.test.tsx
+++ b/packages/react/src/ActionList/Heading.test.tsx
@@ -3,7 +3,7 @@ import {render as HTMLRender} from '@testing-library/react'
import BaseStyles from '../BaseStyles'
import {ActionList} from '.'
import {ActionMenu} from '..'
-import {implementsClassName} from '../utils/testing'
+import {implementsClassName, withExpectedConsoleError} from '../utils/testing'
import classes from './Heading.module.css'
describe('ActionList.Heading', () => {
@@ -42,22 +42,24 @@ describe('ActionList.Heading', () => {
})
it('should throw an error when ActionList.Heading is used within ActionMenu context', async () => {
- expect(() =>
- HTMLRender(
-
-
- Trigger
-
-
- Heading
- Item
-
-
-
- ,
- ),
- ).toThrow(
- "ActionList.Heading shouldn't be used within an ActionMenu container. Menus are labelled by the menu button's name.",
- )
+ withExpectedConsoleError(() => {
+ expect(() =>
+ HTMLRender(
+
+
+ Trigger
+
+
+ Heading
+ Item
+
+
+
+ ,
+ ),
+ ).toThrow(
+ "ActionList.Heading shouldn't be used within an ActionMenu container. Menus are labelled by the menu button's name.",
+ )
+ })
})
})
diff --git a/packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx b/packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx
index a2755af56f0..389b1127649 100644
--- a/packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx
+++ b/packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx
@@ -9,7 +9,7 @@ import {XIcon} from '@primer/octicons-react'
import classes from '../Tooltip.module.css'
import type {JSX} from 'react'
-import {implementsClassName} from '../../utils/testing'
+import {implementsClassName, withExpectedConsoleError} from '../../utils/testing'
const TooltipComponent = (props: Omit & {text?: string}) => (
@@ -125,15 +125,17 @@ describe('Tooltip', () => {
expect(triggerEL.getAttribute('aria-describedby')).toContain('custom-tooltip-id')
})
it('should throw an error if the trigger element is disabled', () => {
- expect(() => {
- HTMLRender(
-
-
- ,
+ withExpectedConsoleError(() => {
+ expect(() => {
+ HTMLRender(
+
+
+ ,
+ )
+ }).toThrow(
+ 'The `Tooltip` component expects a single React element that contains interactive content. Consider using a `