MCPcopy
hub / github.com/TanStack/router / runTest

Function runTest

packages/react-router/tests/searchMiddleware.test.tsx:93–118  ·  view source on GitHub ↗
(
  router: AnyRouter,
  expectedSearch: { root: { value?: string }; posts: { value?: string } },
)

Source from the content-addressed store, hash-verified

91}
92
93async function runTest(
94 router: AnyRouter,
95 expectedSearch: { root: { value?: string }; posts: { value?: string } },
96) {
97 render(<RouterProvider router={router} />)
98
99 const postsLink = await screen.findByTestId('posts-link')
100 expect(postsLink).toHaveAttribute('href')
101 const href = postsLink.getAttribute('href')
102 const linkSearchOnRoot = getSearchParamsFromURI(href!)
103 checkLocationSearch(expectedSearch.root)
104 expect(router.state.location.search).toEqual(expectedSearch.root)
105
106 fireEvent.click(postsLink)
107
108 const postHeading = await screen.findByTestId('posts-heading')
109 expect(postHeading).toBeInTheDocument()
110 expect(window.location.pathname).toBe('/posts')
111
112 expect(await screen.findByTestId('search')).toHaveTextContent(
113 expectedSearch.posts.value ?? '$undefined',
114 )
115 checkLocationSearch(expectedSearch.posts)
116 expect(router.state.location.search).toEqual(expectedSearch.posts)
117 return linkSearchOnRoot
118}
119
120function checkLocationSearch(search: object) {
121 const parsedSearch = new URLSearchParams(window.location.search)

Callers 1

Calls 4

renderFunction · 0.90
getSearchParamsFromURIFunction · 0.90
checkLocationSearchFunction · 0.70
getAttributeMethod · 0.65

Tested by

no test coverage detected