/** * External dependencies */ import { registerPaymentMethodExtensionCallbacks } from '@woocommerce/blocks-registry'; /** * Internal dependencies */ import PaymentMethodConfig from '../payment-method-config'; import * as paymentMethodConfigHelpers from '../payment-method-config-helper'; describe( 'PaymentMethodConfig', () => { let paymentMethod; const spies = {}; beforeEach( () => { spies.canMakePaymentWithExtensions = jest.spyOn( paymentMethodConfigHelpers, 'canMakePaymentWithExtensions' ); paymentMethod = new PaymentMethodConfig( { name: 'test-payment-method', label: 'Test payment method', ariaLabel: 'Test payment method', content:
Test payment content
, edit:
Test payment edit
, canMakePayment: () => true, } ); } ); it( 'Uses canMakePaymentWithExtensions as the canMakePayment function if an extension registers a callback', () => { registerPaymentMethodExtensionCallbacks( 'woocommerce-marketplace-extension', { 'unrelated-payment-method': () => true, } ); // At this point, since no extensions have registered a callback for // test-payment-method we can expect the canMakePayment getter NOT // to execute canMakePaymentWithExtensions. // Disable no-unused-expressions because we just want to test the getter // eslint-disable-next-line no-unused-expressions paymentMethod.canMakePayment; expect( spies.canMakePaymentWithExtensions ).toHaveBeenCalledTimes( 0 ); registerPaymentMethodExtensionCallbacks( 'other-woocommerce-marketplace-extension', { 'test-payment-method': () => true, } ); // Now, because an extension _has_ registered a callback for test-payment-method // The getter will use canMakePaymentWithExtensions to create the // canMakePayment function. // Disable no-unused-expressions because we just want to test the getter // eslint-disable-next-line no-unused-expressions paymentMethod.canMakePayment; expect( spies.canMakePaymentWithExtensions ).toHaveBeenCalledTimes( 1 ); } ); } );