Skip to content

Commit

Permalink
test: We dont use global.location on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
julianajlk committed May 15, 2024
1 parent 0a0d4e4 commit 667e27c
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions src/payment/PageLoadingDynamicPaymentMethods.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ jest.mock('@edx/frontend-platform/logging', () => ({

describe('PageLoadingDynamicPaymentMethods', () => {
let store;
let location;

beforeAll(() => {
location = global.location;
delete global.location;
global.location = { assign: jest.fn() };
});

afterAll(() => {
global.location = location;
});

beforeEach(() => {
store = createStore(createRootReducer());
Expand Down Expand Up @@ -55,7 +44,6 @@ describe('PageLoadingDynamicPaymentMethods', () => {
it('it redirects to receipt page after 3 seconds delay', () => {
const orderNumber = 'EDX-100001';
const logMessage = `Dynamic Payment Methods payment succeeded for edX order number ${orderNumber}, redirecting to ecommerce receipt page.`;
const queryParams = `order_number=${orderNumber}&disable_back_button=${Number(true)}&dpm_enabled=${true}`;
render(
<IntlProvider locale="en">
<Provider store={store}>
Expand All @@ -71,7 +59,6 @@ describe('PageLoadingDynamicPaymentMethods', () => {
jest.advanceTimersByTime(3000);
});
expect(logInfo).toHaveBeenCalledWith(expect.stringMatching(logMessage));
expect(global.location.assign).toHaveBeenCalledWith(expect.stringContaining(`/checkout/receipt/?${queryParams}`));
});

it('cleans up the timer on unmount', () => {
Expand All @@ -85,6 +72,6 @@ describe('PageLoadingDynamicPaymentMethods', () => {
act(() => {
jest.advanceTimersByTime(3000);
});
expect(window.location.assign).not.toHaveBeenCalled();
expect(logInfo).not.toHaveBeenCalled();
});
});

0 comments on commit 667e27c

Please sign in to comment.