Skip to content

Commit

Permalink
Fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
salesfelipe committed Nov 7, 2024
1 parent 1705b59 commit 445143d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions react/__tests__/Gallery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ beforeEach(() => {
jest.clearAllMocks()

mockUseRuntime.mockImplementation(() => ({
route: { routeId: 'routeId' },
getSettings: () => ({}),
}))

Expand Down
17 changes: 11 additions & 6 deletions react/__tests__/components/PriceRange.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
}))
Expand Down Expand Up @@ -62,6 +66,7 @@ const mockProps = {
},
],
preventRouteChange: false,
onChangePriceRange: mockOnChangePriceRange,
}

describe('<PriceRange />', () => {
Expand All @@ -78,11 +83,11 @@ describe('<PriceRange />', () => {

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', () => {
Expand All @@ -93,11 +98,11 @@ describe('<PriceRange />', () => {
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', () => {
Expand Down

0 comments on commit 445143d

Please sign in to comment.