mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2026-07-29 02:07:27 +08:00
No prior test coverage existed for fraudnet.js. Covers the reported crash (confirmed to fail on the pre-fix code with the exact reported ReferenceError), plus the existing happy-path behavior when window.PAYPAL is available.
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
describe( 'fraudnet.js hosted_fields_loaded listener', () => {
|
|
beforeAll( () => {
|
|
global.FraudNetConfig = {
|
|
f: 'fraudnet-session-id',
|
|
s: 'store-id',
|
|
sandbox: '0',
|
|
};
|
|
require( './fraudnet.js' );
|
|
window.dispatchEvent( new Event( 'load' ) );
|
|
} );
|
|
|
|
beforeEach( () => {
|
|
delete window.PAYPAL;
|
|
} );
|
|
|
|
it( 'does not throw when window.PAYPAL is not defined (e.g. c.paypal.com/da/r/fb.js was blocked or has not finished loading yet)', () => {
|
|
expect( () => {
|
|
document.dispatchEvent( new CustomEvent( 'hosted_fields_loaded' ) );
|
|
} ).not.toThrow();
|
|
} );
|
|
|
|
it( 'calls window.PAYPAL.asyncData.initAndCollect() when it is available', () => {
|
|
const initAndCollect = jest.fn();
|
|
window.PAYPAL = { asyncData: { initAndCollect } };
|
|
|
|
document.dispatchEvent( new CustomEvent( 'hosted_fields_loaded' ) );
|
|
|
|
expect( initAndCollect ).toHaveBeenCalledTimes( 1 );
|
|
} );
|
|
|
|
it( 'does not throw and does not call initAndCollect when window.PAYPAL.asyncData.initAndCollect is not a function', () => {
|
|
window.PAYPAL = { asyncData: {} };
|
|
|
|
expect( () => {
|
|
document.dispatchEvent( new CustomEvent( 'hosted_fields_loaded' ) );
|
|
} ).not.toThrow();
|
|
} );
|
|
} );
|