From 445143dcbe0ae8b822ec9af931f696ed912f5b81 Mon Sep 17 00:00:00 2001 From: Felipe Sales Date: Wed, 30 Oct 2024 15:35:49 -0300 Subject: [PATCH] Fix broken tests --- react/__tests__/Gallery.test.js | 1 + react/__tests__/components/PriceRange.test.js | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/react/__tests__/Gallery.test.js b/react/__tests__/Gallery.test.js index 5294d91ae..f10c83334 100644 --- a/react/__tests__/Gallery.test.js +++ b/react/__tests__/Gallery.test.js @@ -19,6 +19,7 @@ beforeEach(() => { jest.clearAllMocks() mockUseRuntime.mockImplementation(() => ({ + route: { routeId: 'routeId' }, getSettings: () => ({}), })) diff --git a/react/__tests__/components/PriceRange.test.js b/react/__tests__/components/PriceRange.test.js index 8598e4ac9..00cf97427 100644 --- a/react/__tests__/components/PriceRange.test.js +++ b/react/__tests__/components/PriceRange.test.js @@ -5,13 +5,17 @@ import { useRuntime } from 'vtex.render-runtime' import PriceRange from '../../components/PriceRange' const mockUseRuntime = useRuntime -const mockSetQuery = jest.fn() +const mockOnChangePriceRange = jest.fn() + +jest.spyOn(window, 'scroll').mockImplementation(jest.fn()) beforeEach(() => { jest.clearAllMocks() mockUseRuntime.mockImplementation(() => ({ - setQuery: mockSetQuery, + query: { + priceRange: {}, + }, getSettings: () => ({}), culture: { country: 'USA', currency: 'USD' }, })) @@ -62,6 +66,7 @@ const mockProps = { }, ], preventRouteChange: false, + onChangePriceRange: mockOnChangePriceRange, } describe('', () => { @@ -78,11 +83,11 @@ describe('', () => { fireEvent.click(getByText('$1.00 $10.00')) - expect(mockSetQuery).not.toBeCalled() + expect(mockOnChangePriceRange).not.toBeCalled() jest.runAllTimers() - expect(mockSetQuery).toHaveBeenCalledTimes(1) + expect(mockOnChangePriceRange).toHaveBeenCalledTimes(1) }) it('should call setQuery on Slider change only once after multiple interactions', () => { @@ -93,11 +98,11 @@ describe('', () => { fireEvent.click(getByText('$1.00 $10.00')) fireEvent.click(getByText('$1.00 $10.00')) - expect(mockSetQuery).not.toBeCalled() + expect(mockOnChangePriceRange).not.toBeCalled() jest.runAllTimers() - expect(mockSetQuery).toHaveBeenCalledTimes(1) + expect(mockOnChangePriceRange).toHaveBeenCalledTimes(1) }) it('should render defaultValues', () => {