Skip to content

Commit

Permalink
Update deprecation warnings, add deprecation unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jul 10, 2024
1 parent 08b9b2c commit a7f8e81
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
14 changes: 7 additions & 7 deletions packages/components/src/composite/legacy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ function proxyComposite< C extends Component >(
): CompositeComponent< C > {
const displayName = ProxiedComponent.displayName;

deprecated( `__unstable${ displayName }`, {
since: '6.7',
alternative: `stable ${ displayName } component`,
} );

const Component = ( legacyProps: CompositeStateProps ) => {
deprecated( `wp.components.__unstable${ displayName }`, {
since: '6.7',
alternative: `the unprefixed, stable version of the ${ displayName } component`,
} );

const { store, ...rest } =
mapLegacyStatePropsToComponentProps( legacyProps );
const props = rest as ComponentProps< C >;
Expand Down Expand Up @@ -196,9 +196,9 @@ export const CompositeItem = proxyComposite( Current.CompositeItem, {
export function useCompositeState(
legacyStateOptions: LegacyStateOptions = {}
): CompositeState {
deprecated( `__unstableUseCompositeState`, {
deprecated( `wp.components.__unstableUseCompositeState`, {
since: '6.7',
alternative: `useCompositeStore hook`,
alternative: `the useCompositeStore hook`,
} );

const {
Expand Down
58 changes: 57 additions & 1 deletion packages/components/src/composite/legacy/test/index.tsx
Original file line number Diff line number Diff line change
@@ -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, sleep, waitFor } from '@ariakit/test';

/**
Expand Down Expand Up @@ -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 the useCompositeStore hook instead.'
);
} );
it( 'Composite', () => {
const Test = () => {
const props = useCompositeState();
return <Composite { ...props } />;
};
render( <Test /> );
expect( console ).toHaveWarnedWith(
'wp.components.__unstableComposite is deprecated since version 6.7. Please use the unprefixed, stable version of the Composite component instead.'
);
} );
it( 'CompositeItem', () => {
const Test = () => {
const props = useCompositeState();
return (
<Composite { ...props }>
<CompositeItem { ...props } />
</Composite>
);
};
render( <Test /> );
expect( console ).toHaveWarnedWith(
'wp.components.__unstableCompositeItem is deprecated since version 6.7. Please use the unprefixed, stable version of the CompositeItem component instead.'
);
} );
it( 'CompositeGroup', () => {
const Test = () => {
const props = useCompositeState();
return (
<Composite { ...props }>
<CompositeGroup { ...props }>
<CompositeItem { ...props } />
</CompositeGroup>
</Composite>
);
};
render( <Test /> );
expect( console ).toHaveWarnedWith(
'wp.components.__unstableCompositeGroup is deprecated since version 6.7. Please use the unprefixed, stable version of the CompositeGroup component instead.'
);
} );
} );

describe.each( [
[
'With "spread" state',
Expand Down

0 comments on commit a7f8e81

Please sign in to comment.