Skip to content

Commit 59ed345

Browse files
authored
Components: Fix no-node-access violations in Disabled tests (#46156)
1 parent 8cf5051 commit 59ed345

File tree

1 file changed

+21
-11
lines changed
  • packages/components/src/disabled/test

1 file changed

+21
-11
lines changed

packages/components/src/disabled/test/index.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,58 @@ describe( 'Disabled', () => {
1818
);
1919

2020
it( 'will disable all fields', () => {
21-
const { container } = render(
22-
<Disabled>
21+
render(
22+
<Disabled data-testid="disabled-wrapper">
2323
<Form />
2424
</Disabled>
2525
);
2626

27-
expect( container.firstChild ).toHaveAttribute( 'inert' );
27+
expect( screen.getByTestId( 'disabled-wrapper' ) ).toHaveAttribute(
28+
'inert'
29+
);
2830
} );
2931

3032
it( 'should cleanly un-disable via reconciliation', () => {
3133
const MaybeDisable = ( { isDisabled = true } ) =>
3234
isDisabled ? (
33-
<Disabled>
35+
<Disabled data-testid="disabled-wrapper">
3436
<Form />
3537
</Disabled>
3638
) : (
3739
<Form />
3840
);
3941

40-
const { container, rerender } = render( <MaybeDisable /> );
42+
const { rerender } = render( <MaybeDisable /> );
4143

42-
expect( container.firstChild ).toHaveAttribute( 'inert' );
44+
expect( screen.getByTestId( 'disabled-wrapper' ) ).toHaveAttribute(
45+
'inert'
46+
);
4347

4448
rerender( <MaybeDisable isDisabled={ false } /> );
4549

46-
expect( container.firstChild ).not.toHaveAttribute( 'inert' );
50+
expect(
51+
screen.queryByTestId( 'disabled-wrapper' )
52+
).not.toBeInTheDocument();
4753
} );
4854

4955
it( 'will disable or enable descendant fields based on the isDisabled prop value', () => {
5056
const MaybeDisable = ( { isDisabled = true } ) => (
51-
<Disabled isDisabled={ isDisabled }>
57+
<Disabled isDisabled={ isDisabled } data-testid="disabled-wrapper">
5258
<Form />
5359
</Disabled>
5460
);
5561

56-
const { rerender, container } = render( <MaybeDisable /> );
62+
const { rerender } = render( <MaybeDisable /> );
5763

58-
expect( container.firstChild ).toHaveAttribute( 'inert' );
64+
expect( screen.getByTestId( 'disabled-wrapper' ) ).toHaveAttribute(
65+
'inert'
66+
);
5967

6068
rerender( <MaybeDisable isDisabled={ false } /> );
6169

62-
expect( container.firstChild ).not.toHaveAttribute( 'inert' );
70+
expect( screen.getByTestId( 'disabled-wrapper' ) ).not.toHaveAttribute(
71+
'inert'
72+
);
6373
} );
6474

6575
it( 'should preserve input values when toggling the isDisabled prop', async () => {

0 commit comments

Comments
 (0)