woocommerce/packages/woocommerce-blocks/assets/js/hocs/test/with-transform-single-select-to-multiple-select.js

35 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-12-10 12:03:04 +00:00
/**
* External dependencies
*/
import TestRenderer from 'react-test-renderer';
/**
* Internal dependencies
*/
import withTransformSingleSelectToMultipleSelect from '../with-transform-single-select-to-multiple-select';
const TestComponent = withTransformSingleSelectToMultipleSelect( ( props ) => {
return <div selected={ props.selected } />;
} );
describe( 'withTransformSingleSelectToMultipleSelect Component', () => {
describe( 'when the API returns an error', () => {
it( 'converts the selected value into an array', () => {
const selected = 123;
const renderer = TestRenderer.create(
<TestComponent selected={ selected } />
);
const props = renderer.root.findByType( 'div' ).props;
expect( props.selected ).toEqual( [ selected ] );
} );
it( 'passes an empty array as the selected prop if selected was null', () => {
const renderer = TestRenderer.create(
<TestComponent selected={ null } />
);
const props = renderer.root.findByType( 'div' ).props;
expect( props.selected ).toEqual( [] );
} );
} );
} );