Skip to content

Commit

Permalink
Fix ScrollToTop test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Bláha committed Feb 1, 2022
1 parent 871b8b2 commit 884a2ed
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions packages/frontend/src/components/ScrollToTop.test.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
import React from "react"
import renderer from "react-test-renderer"
import { MemoryRouter } from "react-router-dom"
import { Router } from "react-router-dom"
import { ScrollToTop } from "./ScrollToTop"
import { createMemoryHistory } from "history"

global.scrollTo = jest.fn()

describe("ScrollToTop", () => {
let wrapper
let history
beforeEach(() => {
wrapper = renderer.create(
<MemoryRouter initialEntries={["/"]}>
it("calls window.scrollTo when route changes", () => {
const history = createMemoryHistory()
renderer.create(
<Router history={history}>
<ScrollToTop />
</MemoryRouter>
</Router>
)
history = wrapper.getInstance().history
})
afterEach(() => {
jest.clearAllMocks()
})

it("calls window.scrollTo when route changes", () => {
expect(global.scrollTo).not.toHaveBeenCalled()
history.push("/new-url")
history.push("/some/route")
expect(global.scrollTo).toHaveBeenCalledWith(0, 0)
})
})

0 comments on commit 884a2ed

Please sign in to comment.