react-code-dataset / wp-calypso /packages /data-stores /src /site-reset /test /use-site-reset-mutation.tsx
react-code-dataset / wp-calypso /packages /data-stores /src /site-reset /test /use-site-reset-mutation.tsx
Download wp-calypso/packages/data-stores/src/site-reset/test/use-site-reset-mutation.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/data-stores/src/site-reset/test/use-site-reset-mutation.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/data-stores/src/site-reset/test/use-site-reset-mutation.tsx
-
curl -L -o use-site-reset-mutation.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/data-stores/src/site-reset/test/use-site-reset-mutation.tsx
2.02 kB
| /** | |
| * @jest-environment jsdom | |
| */ | |
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | |
| import { waitFor } from '@testing-library/dom'; | |
| import { renderHook } from '@testing-library/react'; | |
| import React from 'react'; | |
| import { act } from 'react-dom/test-utils'; | |
| import wpcomRequest from 'wpcom-proxy-request'; | |
| import { useSiteResetMutation } from '../use-site-reset-mutation'; | |
| jest.mock( 'wpcom-proxy-request', () => ( { | |
| __esModule: true, | |
| default: jest.fn(), | |
| } ) ); | |
| describe( 'use-site-reset-mutation hook', () => { | |
| beforeEach( () => { | |
| jest.clearAllMocks(); | |
| } ); | |
| test( 'returns success from the api', async () => { | |
| const queryClient = new QueryClient( { defaultOptions: { queries: { retry: false } } } ); | |
| const wrapper = ( { children } ) => ( | |
| <QueryClientProvider client={ queryClient }>{ children }</QueryClientProvider> | |
| ); | |
| const expected = { | |
| success: true, | |
| }; | |
| ( wpcomRequest as jest.Mock ).mockImplementation( () => Promise.resolve( expected ) ); | |
| const { result } = renderHook( () => useSiteResetMutation(), { | |
| wrapper, | |
| } ); | |
| expect( result.current.isSuccess ).toBe( false ); | |
| act( () => { | |
| result.current.resetSite( 123 ); | |
| } ); | |
| await waitFor( () => { | |
| expect( result.current.isSuccess ).toBe( true ); | |
| expect( result.current.data ).toEqual( expected ); | |
| } ); | |
| } ); | |
| test( 'returns failure from the api', async () => { | |
| const queryClient = new QueryClient(); | |
| const wrapper = ( { children } ) => ( | |
| <QueryClientProvider client={ queryClient }>{ children }</QueryClientProvider> | |
| ); | |
| const error = { | |
| code: 'Unauthorized', | |
| message: 'Something went wrong', | |
| }; | |
| ( wpcomRequest as jest.Mock ).mockImplementation( () => Promise.reject( error ) ); | |
| const { result } = renderHook( () => useSiteResetMutation(), { | |
| wrapper, | |
| } ); | |
| act( () => { | |
| result.current.resetSite( 123 ); | |
| } ); | |
| await waitFor( () => { | |
| expect( result.current.isError ).toBe( true ); | |
| expect( result.current.error ).toEqual( error ); | |
| } ); | |
| } ); | |
| } ); | |