Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion paypal/js/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
isRecurring = 'single' !== settings.one;
const { paypalLayout: layout } = settings;
const cardFieldsAreSupported = layout !== 'checkout_only' && 'function' === typeof window.paypal.CardFields;
const buttonsAreEnabled = layout !== 'card_only' && 'function' === typeof window.paypal.Buttons;
const buttonsAreEnabled = ( isRecurring || layout !== 'card_only' ) && 'function' === typeof window.paypal.Buttons;

const runId = ++initRunId;

Expand Down
10 changes: 7 additions & 3 deletions tests/js/paypalBootstrap.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ async function checkOverlappingInitialization() {
querySelector: () => element,
createElement: () => ( { classList: { add() {} }, append() {} } ),
},
getPayPalSettings: () => [ { one: 'single', paypalLayout: 'checkout_only' } ],
getPayPalSettings: () => [ { one: 'recurring', paypalLayout: 'card_only' } ],
waitForVisiblePaymentField: async () => {},
listenForFieldMutations() {},
listenForSubmitButtonMutations() {},
paymentMethods: methods,
discoverPaymentMethods: async () => methods.set( 'paypal', { eligible: true, render: async () => {} } ),
discoverPaymentMethods: async ( { buttonsAreEnabled } ) => {
if ( buttonsAreEnabled ) {
methods.set( 'paypal', { eligible: true, render: async () => {} } );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty async method 'render'


Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.

}
},
Comment on lines +100 to +104

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found `async` function without any `await` expressions


A function that does not contain any await expressions should not be async (except for some edge cases in TypeScript which are discussed below). Asynchronous functions in JavaScript behave differently than other functions in two important ways:

discoverDeferredPaymentMethods: () => {
waiting++; return gate;
},
Expand All @@ -123,7 +127,7 @@ async function checkOverlappingInitialization() {
assert.equal( selectorCount, 1, 'Only the latest run should render the payment selector.' );
}

test( 'PayPal renders only the latest initialization after asynchronous discovery', checkOverlappingInitialization );
test( 'PayPal renders only the latest subscription buttons with a saved Card only layout', checkOverlappingInitialization );

test( 'superseded wallet discovery does not register methods in the current run', async () => {
const start = source.indexOf( '\tasync function discoverDeferredPaymentMethods(' );
Expand Down