Server IP : 104.21.14.103 / Your IP : 3.15.219.174 Web Server : LiteSpeed System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : giankuin ( 1871) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/home/giankuin/sieuthiweb.com.vn/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/base/hooks/checkout/test/ |
Upload File : |
/** * External dependencies */ import TestRenderer, { act } from 'react-test-renderer'; import { createRegistry, RegistryProvider } from '@wordpress/data'; /** * Internal dependencies */ import { useCheckoutSubmit } from '../use-checkout-submit'; const mockUseCheckoutContext = { onSubmit: jest.fn(), }; const mockUsePaymentMethodDataContext = {}; const mockUsePaymentMethods = { paymentMethods: {}, }; jest.mock( '@woocommerce/base-context', () => ( { useCheckoutContext: () => mockUseCheckoutContext, usePaymentMethodDataContext: () => mockUsePaymentMethodDataContext, } ) ); jest.mock( '@woocommerce/base-hooks', () => ( { usePaymentMethods: () => mockUsePaymentMethods, } ) ); describe( 'useCheckoutSubmit', () => { let registry, renderer; const getWrappedComponents = ( Component ) => ( <RegistryProvider value={ registry }> <Component /> </RegistryProvider> ); const getTestComponent = () => () => { const data = useCheckoutSubmit(); return <div { ...data } />; }; beforeEach( () => { registry = createRegistry(); renderer = null; } ); it( 'onSubmit calls the correct action in the checkout context', () => { const TestComponent = getTestComponent(); act( () => { renderer = TestRenderer.create( getWrappedComponents( TestComponent ) ); } ); const { onSubmit } = renderer.root.findByType( 'div' ).props; onSubmit(); expect( mockUseCheckoutContext.onSubmit ).toHaveBeenCalledTimes( 1 ); } ); } );