woocommerce/packages/woocommerce-blocks/assets/js/base/context/test/utils.js
2021-12-10 12:03:04 +00:00

54 lines
1.0 KiB
JavaScript

/**
* Internal dependencies
*/
import { assertValidContextValue } from '../utils';
describe( 'assertValidContextValue', () => {
const contextName = 'testContext';
const validationMap = {
cheeseburger: {
required: false,
type: 'string',
},
amountKetchup: {
required: true,
type: 'number',
},
};
it.each`
testValue
${ {} }
${ 10 }
${ { amountKetchup: '10' } }
`(
'The value of $testValue is expected to trigger an Error',
( { testValue } ) => {
const invokeTest = () => {
assertValidContextValue(
contextName,
validationMap,
testValue
);
};
expect( invokeTest ).toThrow();
}
);
it.each`
testValue
${ { amountKetchup: 20 } }
${ { cheeseburger: 'fries', amountKetchup: 20 } }
`(
'The value of $testValue is not expected to trigger an Error',
( { testValue } ) => {
const invokeTest = () => {
assertValidContextValue(
contextName,
validationMap,
testValue
);
};
expect( invokeTest ).not.toThrow();
}
);
} );