Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0b186bf
chore: rename useTab to useSearchParamsKey and add test
Parkreiner Feb 19, 2024
a7a0944
chore: mark old renderHookWithAuth as deprecated (temp)
Parkreiner Feb 19, 2024
ec3ba4f
fix: update imports for useResourcesNav
Parkreiner Feb 19, 2024
6d7ef9f
Merge branch 'main' into mes/hook-test-revamps-4
Parkreiner Mar 3, 2024
afffb26
refactor: change API for useSearchParamsKey
Parkreiner Mar 3, 2024
590f02b
chore: let user pass in their own URLSearchParams value
Parkreiner Mar 3, 2024
9e00ea6
refactor: clean up comments for clarity
Parkreiner Mar 3, 2024
d7110c5
fix: update import
Parkreiner Mar 3, 2024
2cc63d7
wip: commit progress on useWorkspaceDuplication revamp
Parkreiner Mar 3, 2024
26089e3
chore: migrate duplication test to new helper
Parkreiner Mar 3, 2024
8057397
refactor: update code for clarity
Parkreiner Mar 3, 2024
f8f87a3
refactor: reorder test cases for clarity
Parkreiner Mar 3, 2024
dcc89dc
refactor: split off hook helper into separate file
Parkreiner Mar 3, 2024
1ab6f03
refactor: remove reliance on internal React Router state property
Parkreiner Mar 4, 2024
b32603f
refactor: move variables around for more clarity
Parkreiner Mar 4, 2024
b0fabde
refactor: more updates for clarity
Parkreiner Mar 4, 2024
b94decc
refactor: reorganize test cases for clarity
Parkreiner Mar 4, 2024
3e41877
refactor: clean up test cases for useWorkspaceDupe
Parkreiner Mar 8, 2024
1fcf9e2
refactor: clean up test cases for useWorkspaceDupe
Parkreiner Mar 8, 2024
13f5e53
Merge branch 'main' into mes/hook-test-revamps-4
Parkreiner Mar 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: clean up comments for clarity
  • Loading branch information
Parkreiner committed Mar 3, 2024
commit 9e00ea66f88522521acabed568284c6e5a8b37fb
21 changes: 11 additions & 10 deletions site/src/testHelpers/renderHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,16 @@ export async function renderHookWithAuth<Result, Props>(
} = routingOptions;

/**
* Have to do some incredibly, incredibly cursed things here. Scoured the
* tests for the React Router source code, and from their examples, there
* didn't appear to be any examples of them letting you expose the router
* directly. (One of the tests created a dummy paragraph, and injected the
* values into that...)
* Have to do some cursed things here. Scoured the tests for the React Router
* source code, and from their examples, there didn't appear to be any
* examples of them letting you expose the router directly. (One of the tests
* created a dummy paragraph, and injected the values into that...)
*
* This breaks some rules, but it makes sure that the code is resilient to
* re-renders, and hopefully removes the need to make every test file that
* uses this function support JSX.
* This breaks some React rules, but it makes sure that the code is resilient
* to re-renders, and hopefully removes the need to make every test file that
* uses renderHookWithAuth be defined as a .tsx file just to add dummy JSX.
*/
// Easy to miss - evil definite assignment
// Easy to miss - evil definite assignment with !
let escapedLocation!: ReturnType<typeof useLocation>;
const LocationLeaker: FC<PropsWithChildren> = ({ children }) => {
const location = useLocation();
Expand Down Expand Up @@ -252,7 +251,9 @@ export async function renderHookWithAuth<Result, Props>(
await waitFor(() => expect(result.current).not.toBe(null));

if (escapedLocation === undefined) {
throw new Error("Failed definite initialization for location during setup");
throw new Error(
"Location is unavailable even after custom hook value is ready",
);
}

return {
Expand Down