2019-11-14 14:51:32 +00:00
|
|
|
/**
|
|
|
|
* 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`
|
2021-03-10 15:03:26 +00:00
|
|
|
testValue
|
|
|
|
${ {} }
|
|
|
|
${ 10 }
|
|
|
|
${ { amountKetchup: '10' } }
|
2019-11-14 14:51:32 +00:00
|
|
|
`(
|
2021-03-10 15:03:26 +00:00
|
|
|
'The value of $testValue is expected to trigger an Error',
|
|
|
|
( { testValue } ) => {
|
2019-11-14 14:51:32 +00:00
|
|
|
const invokeTest = () => {
|
|
|
|
assertValidContextValue(
|
|
|
|
contextName,
|
|
|
|
validationMap,
|
|
|
|
testValue
|
|
|
|
);
|
|
|
|
};
|
2021-03-10 15:03:26 +00:00
|
|
|
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();
|
2019-11-14 14:51:32 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|