File size: 1,038 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/**
* @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 );
} );
} );
|