Skip to content

Instantly share code, notes, and snippets.

@lmiller1990
Created July 24, 2018 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmiller1990/927828ea5ec4036f25cbb2fa19f5c612 to your computer and use it in GitHub Desktop.
Save lmiller1990/927828ea5ec4036f25cbb2fa19f5c612 to your computer and use it in GitHub Desktop.
import { beforeEach } from "@/router.js"
import mockModule from "@/bust-cache.js"
jest.mock("@/bust-cache.js", () => ({ bustCache: jest.fn() }))
describe("beforeEach", () => {
afterEach(() => {
mockModule.bustCache.mockClear()
})
it("busts the cache when going to /user", () => {
const to = {
matched: [{ meta: { shouldBustCache: true } }]
}
const next = jest.fn()
beforeEach(to, undefined, next)
expect(mockModule.bustCache).toHaveBeenCalled()
expect(next).toHaveBeenCalled()
})
it("busts the cache when going to /user", () => {
const to = {
matched: [{ meta: { shouldBustCache: false } }]
}
const next = jest.fn()
beforeEach(to, undefined, next)
expect(mockModule.bustCache).not.toHaveBeenCalled()
expect(next).toHaveBeenCalled()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment