Skip to content

Commit

Permalink
Update unit tests to expect the warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Sep 5, 2024
1 parent 2ac1e6e commit aee7a65
Showing 1 changed file with 57 additions and 1 deletion.
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, 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 Composite.useStore 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 Composite 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 Composite.Item 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 Composite.Group or Composite.Row instead.'
);
} );
} );

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

0 comments on commit aee7a65

Please sign in to comment.