-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
53 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import { renderHook, waitFor } from 'test/test-utils'; | ||
|
||
import * as UseAuth from 'hooks/useAuth'; | ||
import { userTokensFixture } from '__fixtures__/tokens'; | ||
|
||
import { useAxios } from 'hooks/useAxios'; | ||
|
||
describe('useAxios', () => { | ||
const useAuthSpy = vi.spyOn(UseAuth, 'useAuth'); | ||
const refetchUserTokensMock = vi.fn(); | ||
|
||
beforeEach(() => { | ||
useAuthSpy.mockReturnValue({ | ||
isAuthenticated: true, | ||
userToken: userTokensFixture, | ||
refetchUserTokens: refetchUserTokensMock, | ||
}); | ||
}); | ||
|
||
it('should return context', async () => { | ||
// ARRANGE | ||
const { result } = renderHook(() => useAxios()); | ||
await waitFor(() => expect(result.current).not.toBeNull()); | ||
|
||
// ASSERT | ||
expect(result.current).toBeDefined(); | ||
expect(result.current.request).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useContext } from 'react'; | ||
import { AxiosInstance } from 'axios'; | ||
|
||
import { AxiosContext } from 'providers/AxiosProvider'; | ||
|
||
/** | ||
* The `useAxios` hook returns the current `AxiosContext` value. | ||
* @returns {AxiosInstance} The current `AxiosContext` value, an `AxiosInstance`. | ||
*/ | ||
export const useAxios = (): AxiosInstance => { | ||
return useContext(AxiosContext); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters