Skip to content

TypeError: routes.set is not a function unit tests #74

@ritchieanesco

Description

@ritchieanesco

I'm writing unit tests to validate correct pages are appearing on navigation change. I am using Svelte Testing Library.

I can not provide the actual code due to privacy reasons but here is the gist of it.

App.svelte

<script lang="ts">
  import { Router, routes } from "svelte-hash-router"
  import PageOne from "./PageOne.svelte"
  routes.set({
    "page-one": PageOne
  })
</script>

App.test.ts

it('should render header', async () => {
  const { getByTestId } = render(App)
  window.location.href = "/#/page-one"
  await waitFor(() => getByTestId("header"))
  expect(getByTestId("title")).toBeInTheDocument()
})

it("should render main", async () => {
  const { getByTestId } = render(App)
  window.location.href = "/#/page-one"
  await waitFor(() => getByTestId("main"))
})

When I run the tests the first one passes, but the second test outputs the following error: TypeError: routes.set is not a function

I had a look through the code and noticed this:

https://github.com/pynnl/svelte-hash-router/blob/1afbdc9b7945b8f3a7d576692c58ab97ab722652/src/utils/routes.js#L54

I'm wondering why set needs to be removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions