From baa4961dbe972f186b57b495d405943d86a3ec4c Mon Sep 17 00:00:00 2001 From: nicholas Date: Fri, 29 Nov 2024 09:54:08 +0100 Subject: [PATCH] Refactored unit test --- .../lib/src/components/Klarna/KlarnaPayments.test.tsx | 9 +++------ .../components/KlarnaContainer/KlarnaContainer.tsx | 2 +- packages/lib/src/components/Klarna/types.ts | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/lib/src/components/Klarna/KlarnaPayments.test.tsx b/packages/lib/src/components/Klarna/KlarnaPayments.test.tsx index 0903306081..d7db6d278e 100644 --- a/packages/lib/src/components/Klarna/KlarnaPayments.test.tsx +++ b/packages/lib/src/components/Klarna/KlarnaPayments.test.tsx @@ -22,7 +22,7 @@ describe('KlarnaPayments', () => { expect(screen.queryByRole('button', { name: 'Continue to Pay By Bank' })).toBeFalsy(); }); - test('should call setStatus if elementRef is a drop-in', async () => { + test('should call setStatus if elementRef is a drop-in', () => { const KlarnaPaymentsEle = new KlarnaPayments(global.core, { ...coreProps, ...{ paymentData: '', paymentMethodType: '', sdkData: undefined, useKlarnaWidget: false, showPayButton: false } @@ -30,10 +30,7 @@ describe('KlarnaPayments', () => { KlarnaPaymentsEle.elementRef = new Dropin(global.core); render(KlarnaPaymentsEle.render()); const spy = jest.spyOn(KlarnaPaymentsEle.elementRef, 'setStatus'); - // @ts-ignore to test - await waitFor(() => KlarnaPaymentsEle.componentRef); - // @ts-ignore to test - KlarnaPaymentsEle.componentRef.props.onLoaded(); + KlarnaPaymentsEle.onLoaded(); expect(spy).toHaveBeenCalled(); }); @@ -55,7 +52,7 @@ describe('KlarnaPayments', () => { // @ts-ignore to test await waitFor(() => KlarnaPaymentsEle.componentRef); // @ts-ignore to test - KlarnaPaymentsEle.componentRef.props.onComplete(); + KlarnaPaymentsEle.componentRef.onComplete(); expect(onAdditionalDetailsMock).toHaveBeenCalled(); }); }); diff --git a/packages/lib/src/components/Klarna/components/KlarnaContainer/KlarnaContainer.tsx b/packages/lib/src/components/Klarna/components/KlarnaContainer/KlarnaContainer.tsx index 378e6888d7..c06bd732f9 100644 --- a/packages/lib/src/components/Klarna/components/KlarnaContainer/KlarnaContainer.tsx +++ b/packages/lib/src/components/Klarna/components/KlarnaContainer/KlarnaContainer.tsx @@ -19,7 +19,7 @@ export function KlarnaContainer(props) { klarnaContainerRef.current.setAction = setAction; klarnaContainerRef.current.setStatus = setStatus; - klarnaContainerRef.current.props = props; // Needed for unit tests + klarnaContainerRef.current.onComplete = props.onComplete; // Needed for unit tests if (action.sdkData) { return ( diff --git a/packages/lib/src/components/Klarna/types.ts b/packages/lib/src/components/Klarna/types.ts index 13e2bbbcf2..0622c52a20 100644 --- a/packages/lib/src/components/Klarna/types.ts +++ b/packages/lib/src/components/Klarna/types.ts @@ -64,5 +64,5 @@ export interface KlarnaAction { export interface KlarnaContainerRef extends ComponentMethodsRef { initWidget?: () => void; setAction?(action: KlarnaAction): void; - props?: any; + onComplete?: (state: any) => void; }