From aee7a6533547608d93e2db9dc528666ab42f9a39 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Mon, 15 Jul 2024 16:28:12 +0200 Subject: [PATCH] Update unit tests to expect the warnings --- .../src/composite/legacy/test/index.tsx | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/packages/components/src/composite/legacy/test/index.tsx b/packages/components/src/composite/legacy/test/index.tsx index 07398e54b27ca3..8b2125397d70d1 100644 --- a/packages/components/src/composite/legacy/test/index.tsx +++ b/packages/components/src/composite/legacy/test/index.tsx @@ -1,7 +1,12 @@ /** * External dependencies */ -import { queryByAttribute, render, screen } from '@testing-library/react'; +import { + queryByAttribute, + render, + screen, + renderHook, +} from '@testing-library/react'; import { press, waitFor } from '@ariakit/test'; /** @@ -156,6 +161,57 @@ function getShiftTestItems() { }; } +// Checking for deprecation warnings before other tests because the `deprecated` +// utility only fires a console.warn the first time a component is rendered. +describe( 'Shows a deprecation warning', () => { + it( 'useCompositeState', () => { + renderHook( () => useCompositeState() ); + expect( console ).toHaveWarnedWith( + 'wp.components.__unstableUseCompositeState is deprecated since version 6.7. Please use Composite.useStore instead.' + ); + } ); + it( 'Composite', () => { + const Test = () => { + const props = useCompositeState(); + return ; + }; + render( ); + expect( console ).toHaveWarnedWith( + 'wp.components.__unstableComposite is deprecated since version 6.7. Please use Composite instead.' + ); + } ); + it( 'CompositeItem', () => { + const Test = () => { + const props = useCompositeState(); + return ( + + + + ); + }; + render( ); + expect( console ).toHaveWarnedWith( + 'wp.components.__unstableCompositeItem is deprecated since version 6.7. Please use Composite.Item instead.' + ); + } ); + it( 'CompositeGroup', () => { + const Test = () => { + const props = useCompositeState(); + return ( + + + + + + ); + }; + render( ); + expect( console ).toHaveWarnedWith( + 'wp.components.__unstableCompositeGroup is deprecated since version 6.7. Please use Composite.Group or Composite.Row instead.' + ); + } ); +} ); + describe.each( [ [ 'With "spread" state',