Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(RadioList): the radio-group summary reads each state's result instead of checking every state again (#10206)

Cindy Zhang097955952cbb
diff --git a/packages/core/src/RadioList/__tests__/RadioGroup.a11y.test.tsx b/packages/core/src/RadioList/__tests__/RadioGroup.a11y.test.tsx
index e0a7ce2c72..bc695c7ac7 100644
--- a/packages/core/src/RadioList/__tests__/RadioGroup.a11y.test.tsx
+++ b/packages/core/src/RadioList/__tests__/RadioGroup.a11y.test.tsx
@@ -12,8 +12,6 @@ import {cleanup, render, screen} from '@testing-library/react';
import {describe, expect, it} from 'vitest';
import {
RADIO_GROUP_PATTERN,
- checkAccessibilitySpec,
- createJsdomHarness,
expectAccessibilitySpec,
summarize,
unmatchedKnownFailures,
@@ -34,8 +32,10 @@ function subjectFor(state: RadioGroupBindingRow): Element {
});
}
-async function expectState(state: RadioGroupBindingRow): Promise<void> {
- await expectAccessibilitySpec({
+async function expectState(
+ state: RadioGroupBindingRow,
+): Promise<BindingResult> {
+ return expectAccessibilitySpec({
spec: RADIO_GROUP_PATTERN,
binding: state.binding,
state: state.id,
@@ -49,36 +49,24 @@ async function expectState(state: RadioGroupBindingRow): Promise<void> {
});
}
-async function checkState(state: RadioGroupBindingRow): Promise<BindingResult> {
- return checkAccessibilitySpec({
- spec: RADIO_GROUP_PATTERN,
- binding: state.binding,
- state: state.id,
- facts: state.facts,
- knownFailures: RADIO_GROUP_KNOWN_FAILURES,
- mount: async () => {
- render(RADIO_GROUP_STATE_RENDERS[state.id]());
- return createJsdomHarness({subject: subjectFor(state)});
- },
- unmount: cleanup,
- });
-}
-
describe('the shared radio-group pattern, jsdom lane', () => {
+ // Each state renders and checks once. The summary reads these results, so
+ // the suite does not check every state a second time in one long test.
+ const results: BindingResult[] = [];
+
it.each(
RADIO_GROUP_BINDING_STATES.map(
state =>
[`${state.binding} [${state.id}]`, state.summary, state] as const,
),
)('%s — %s', async (_id, _summary, state) => {
- await expectState(state);
+ results.push(await expectState(state));
});
- it('runs the DOM layer and reports higher layers as unrun', async () => {
- const results: BindingResult[] = [];
- for (const state of RADIO_GROUP_BINDING_STATES) {
- results.push(await checkState(state));
- }
+ it('runs the DOM layer and reports higher layers as unrun', () => {
+ expect(results.map(result => result.state)).toEqual(
+ RADIO_GROUP_BINDING_STATES.map(state => state.id),
+ );
const report = summarize(RADIO_GROUP_PATTERN, results);
expect(report.counts.pass).toBeGreaterThan(0);
expect(report.unrunLayers).toEqual(['accessibility-tree', 'real-browser']);