Download wp-calypso/client/landing/stepper/hooks/test/use-countries.jsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/landing/stepper/hooks/test/use-countries.jsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/landing/stepper/hooks/test/use-countries.jsx
-
curl -L -o use-countries.jsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/landing/stepper/hooks/test/use-countries.jsx
1.04 kB
| /** | |
| * @jest-environment jsdom | |
| */ | |
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | |
| import { renderHook, waitFor } from '@testing-library/react'; | |
| import nock from 'nock'; | |
| import { useCountries } from '../use-countries'; | |
| describe( 'use-countries hook', () => { | |
| test( 'returns list of countries from the api', async () => { | |
| const queryClient = new QueryClient(); | |
| const wrapper = ( { children } ) => ( | |
| <QueryClientProvider client={ queryClient }>{ children }</QueryClientProvider> | |
| ); | |
| const expected = { | |
| 'AL:AL-01': 'Albania — Berat', | |
| 'AL:AL-09': 'Albania — Dibër', | |
| 'AL:AL-02': 'Albania — Durrës', | |
| 'AL:AL-03': 'Albania — Elbasan', | |
| }; | |
| nock( 'https://public-api.wordpress.com' ) | |
| .get( '/wpcom/v2/woocommerce/countries/regions/' ) | |
| .reply( 200, expected ); | |
| const { result } = renderHook( () => useCountries(), { | |
| wrapper, | |
| } ); | |
| await waitFor( () => expect( result.current.isSuccess ).toBe( true ) ); | |
| expect( result.current.data ).toEqual( expected ); | |
| } ); | |
| } ); | |