Skip to content

Commit

Permalink
test: fixed failed useSearchRep() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kilip committed Oct 25, 2023
1 parent d4f301b commit 6bf3f9c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/pkg/github/hooks/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { renderHook, waitFor } from '@testing-library/react'
import fetchMock from 'fetch-mock'
import { describe, expect, it } from 'vitest'
import useSearchRepos from './search'
import { wrapper } from 'test/queryClientWrapper'
import { createReactQueryWrapper } from 'test/wrapper'
import { GitHubSearchProvider } from '../context/SearchContext'

const wrapper = createReactQueryWrapper([GitHubSearchProvider])
describe('useSearchRepos()', () => {
it('should search repos', async () => {
const expected = { hello: 'world' }
Expand Down
2 changes: 0 additions & 2 deletions src/pkg/github/hooks/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { useGitHubSearchContext } from '../context/SearchContext'
import { GitHubSearchResponse } from '../types'
import { GitHub } from '../GitHub'
import { api } from '@/pkg/utils/fetch'
import { useThemeContext } from '@/pkg/ui/contexts/ThemeContext'

export default function useSearchRepos() {
const { queryParams: params } = useGitHubSearchContext()
const { setLoading } = useThemeContext()

const result = useQuery({
queryKey: [GitHub.search.queryKey, { params }],
Expand Down
17 changes: 0 additions & 17 deletions test/queryClientWrapper.tsx

This file was deleted.

26 changes: 26 additions & 0 deletions test/wrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ComposeProviders from '@/pkg/ui/ComposeProviders'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { JSXElementConstructor, PropsWithChildren } from 'react'

export function createReactQueryWrapper(
components: Array<JSXElementConstructor<PropsWithChildren<any>>>,
qc?: QueryClient
) {
if (!qc) {
qc = new QueryClient({
defaultOptions: {
queries: {
retry: false,
},
},
})
}

const wrapper = ({ children }: PropsWithChildren) => (
<QueryClientProvider client={qc as QueryClient}>
<ComposeProviders components={components}>{children}</ComposeProviders>
</QueryClientProvider>
)

return wrapper
}

0 comments on commit 6bf3f9c

Please sign in to comment.