Skip to content

Commit

Permalink
test with render hook libaray
Browse files Browse the repository at this point in the history
  • Loading branch information
Liz Johnson committed Sep 16, 2023
1 parent d3105d5 commit e865623
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions frontend/src/hooks/useParticipants.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {AxiosInstance} from "axios";
import useParticipants from "./useParticipants";
import React from "react";
import {useHttpClient} from "./useHttpClient";
import { renderHook } from '@testing-library/react'

jest.mock("./useHttpClient")

Expand Down Expand Up @@ -66,4 +67,17 @@ describe('useParticipants', () => {
expect(screen.getByText(/1/)).not.toBeNull()
})
});
it("automatically fetches the given URL when called", async () => {
const { result } = renderHook(() => useParticipants())

await waitFor(() => {
expect(result.current.participants).toEqual([{
"id":1,
"first_name":"clayton",
"last_name":"johnson",
"birthdate":"2016-04-16"
}])
expect(mockHttpClient.get).toHaveBeenCalledWith('/participants')
})
})
});

0 comments on commit e865623

Please sign in to comment.