Skip to content

Commit 512b222

Browse files
committed
fix(react-tags): cast slot props in regression tests to satisfy TS
1 parent 3b845a3 commit 512b222

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

packages/react-components/react-tags/library/src/components/Tag/useTag.test.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ describe('useTagBase_unstable', () => {
7777
it('should attach onClick/onKeyDown handlers when dismissible', () => {
7878
const ref = React.createRef<HTMLElement>();
7979
const { result } = renderHook(() => useTagBase_unstable({ dismissible: true }, ref), { wrapper: wrap() });
80-
expect(result.current.root.onClick).toBeDefined();
81-
expect(result.current.root.onKeyDown).toBeDefined();
82-
expect(result.current.root.type).toBe('button');
80+
const root = result.current.root as React.ButtonHTMLAttributes<HTMLButtonElement>;
81+
expect(root.onClick).toBeDefined();
82+
expect(root.onKeyDown).toBeDefined();
83+
expect(root.type).toBe('button');
8384
});
8485

8586
it('should NOT inject a default dismissIcon children (icon injection lives in the styled hook)', () => {
@@ -112,7 +113,8 @@ describe('useTagBase_unstable', () => {
112113
wrapper: wrap({ handleTagDismiss: () => ({}), size: 'medium', disabled: true }),
113114
});
114115
expect(result.current.disabled).toBe(true);
115-
expect(result.current.root.disabled).toBe(true);
116+
const root = result.current.root as React.ButtonHTMLAttributes<HTMLButtonElement>;
117+
expect(root.disabled).toBe(true);
116118
});
117119

118120
it('should inherit dismissible from TagGroupContext when not set on props', () => {
@@ -121,6 +123,7 @@ describe('useTagBase_unstable', () => {
121123
wrapper: wrap({ handleTagDismiss: () => ({}), size: 'medium', dismissible: true }),
122124
});
123125
expect(result.current.dismissible).toBe(true);
124-
expect(result.current.root.type).toBe('button');
126+
const root = result.current.root as React.ButtonHTMLAttributes<HTMLButtonElement>;
127+
expect(root.type).toBe('button');
125128
});
126129
});

packages/react-components/react-tags/library/src/components/TagGroup/useTagGroup.test.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { renderHook } from '@testing-library/react-hooks';
22
import * as React from 'react';
3+
import type { TabsterDOMAttribute } from '@fluentui/react-tabster';
34

45
import { useTagGroup_unstable, useTagGroupBase_unstable } from './useTagGroup';
56

7+
// Slot props are a discriminated union that doesn't expose `data-*` index access at
8+
// the type level; cast to a plain record for the data-attribute assertions below.
9+
type RootRecord = Record<string, unknown>;
10+
611
describe('useTagGroup_unstable', () => {
712
it('should default size to medium and appearance to filled', () => {
813
const ref = React.createRef<HTMLDivElement>();
@@ -18,7 +23,7 @@ describe('useTagGroup_unstable', () => {
1823

1924
// useTagGroup_unstable wires up useArrowNavigationGroup via the base hook's
2025
// arrowNavigationProps option; Tabster's contract is a data-tabster attribute.
21-
expect(result.current.root['data-tabster']).toBeDefined();
26+
expect((result.current.root as RootRecord)['data-tabster']).toBeDefined();
2227
});
2328

2429
it('should default role to toolbar', () => {
@@ -33,16 +38,15 @@ describe('useTagGroupBase_unstable', () => {
3338
it('should NOT include arrow-navigation props when options omitted (true headless mode)', () => {
3439
const ref = React.createRef<HTMLDivElement>();
3540
const { result } = renderHook(() => useTagGroupBase_unstable({}, ref));
36-
expect(result.current.root['data-tabster']).toBeUndefined();
41+
expect((result.current.root as RootRecord)['data-tabster']).toBeUndefined();
3742
});
3843

3944
it('should spread arrowNavigationProps option onto root when supplied', () => {
4045
const ref = React.createRef<HTMLDivElement>();
41-
const arrowNavigationProps = { 'data-arrow': 'group', tabIndex: 0 };
46+
const arrowNavigationProps: TabsterDOMAttribute = { 'data-tabster': '{"mock":"value"}' };
4247
const { result } = renderHook(() => useTagGroupBase_unstable({}, ref, { arrowNavigationProps }));
4348

44-
expect(result.current.root['data-arrow']).toBe('group');
45-
expect(result.current.root.tabIndex).toBe(0);
49+
expect((result.current.root as RootRecord)['data-tabster']).toBe('{"mock":"value"}');
4650
});
4751

4852
it('should call onAfterTagDismiss with the group container after a tag is dismissed', () => {

0 commit comments

Comments
 (0)