File "utils.js"

Full Path: /home/vantageo/public_html/cache/cache/.wp-cli/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/base/context/test/utils.js
File size: 1 KB
MIME-type: text/x-java
Charset: utf-8

/**
 * 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();
		}
	);
} );