AlexxNB / tinro

Highly declarative, tiny, dependency free router for Svelte's web applications.
MIT License
669 stars 30 forks source link

router.goto not working in testing-library #44

Closed ritchieanesco closed 3 years ago

ritchieanesco commented 3 years ago

Description When using version 0.4.6 I was able to use router.goto to navigate to the home page to setup each of my tests due to router state persisting between test. With the update to 0.5.3 router.goto has stopped working.

Example

Test file:

import { fireEvent, render, screen, waitFor } from "@testing-library/svelte"
import { router } from "tinro"
import App from "@/App.svelte"

beforeEach(() => { router.goto("/") })

it("should navigate to page b", async () => {
  render(App)
  expect(screen.getByTestId("home")).toBeInTheDocument()
  await fireEvent.click(screen.getByText("Page B"))
  await waitFor(() => expect(screen.getByTestId("page-b")).toBeInTheDocument())
})

it("should navigate to page c", async () => {
  render(App)
  // the following fails as route state persists from previous test.
  expect(screen.getByTestId("home")).toBeInTheDocument()
  await fireEvent.click(screen.getByText("Page C"))
  await waitFor(() => expect(screen.getByTestId("page-c")).toBeInTheDocument())
})

Routes component:

<script lang="ts">
  import { Route } from "tinro"
  import Home from "./home.svelte"
  import PageC from "./page-c.svelte"
  import PageB from "./page-b.svelte"
</script>

<Route>
  <Route path="/page-c"><PageC /></Route>
  <Route path="/page-b"><PageB /></Route>
  <Route path="/"><Home /></Route>
</Route>

tinro version: 0.5.3 svelte version: 3.31.2

ritchieanesco commented 3 years ago

After some digging around the router.goto seems to be working as expected. Push states are being updated, to do this i just logged out the {$router.path} on the routes widget, unfortunately the page is just not reflecting the change.

AlexxNB commented 3 years ago

I'm not familar with @testing-library/svelte. Trying to use router.goto() in the simple app working great. Could you provide minimal example with testing-library for me(repo or zip)?

ritchieanesco commented 3 years ago

@AlexxNB i've attached a zip replicating the issue. Thanks for taking the time to look into this.

test.zip

AlexxNB commented 3 years ago

fixed in v.0.5.5