Skip to content

Commit

Permalink
test: ✅ update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
matteoscurati committed Oct 24, 2024
1 parent 6403266 commit e50d6f9
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions ui/hooks/metamask-notifications/useProfileSyncing.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import React, { ReactNode } from 'react';
import { Provider } from 'react-redux';
import { Store } from 'redux';
import { renderHook, act } from '@testing-library/react-hooks';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { waitFor } from '@testing-library/react';
import { MetamaskNotificationsProvider } from '../../contexts/metamask-notifications';
import * as actions from '../../store/actions';
import {
useEnableProfileSyncing,
Expand Down Expand Up @@ -77,12 +79,26 @@ const arrangeMocks = (
return { store };
};

const RenderWithProviders = ({
store,
children,
}: {
store: Store;
children: ReactNode;
}) => (
<Provider store={store}>
<MetamaskNotificationsProvider>{children}</MetamaskNotificationsProvider>
</Provider>
);

describe('useProfileSyncing', () => {
it('should enable profile syncing', async () => {
const { store } = arrangeMocks();

const { result } = renderHook(() => useEnableProfileSyncing(), {
wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
wrapper: ({ children }) => (
<RenderWithProviders store={store}>{children}</RenderWithProviders>
),
});

act(() => {
Expand All @@ -96,7 +112,9 @@ describe('useProfileSyncing', () => {
const { store } = arrangeMocks();

const { result } = renderHook(() => useDisableProfileSyncing(), {
wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
wrapper: ({ children }) => (
<RenderWithProviders store={store}>{children}</RenderWithProviders>
),
});

act(() => {
Expand All @@ -113,7 +131,9 @@ describe('useProfileSyncing', () => {
});

renderHook(() => useAccountSyncingEffect(), {
wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
wrapper: ({ children }) => (
<RenderWithProviders store={store}>{children}</RenderWithProviders>
),
});

await waitFor(() => {
Expand All @@ -125,7 +145,9 @@ describe('useProfileSyncing', () => {
const { store } = arrangeMocks();

renderHook(() => useAccountSyncingEffect(), {
wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
wrapper: ({ children }) => (
<RenderWithProviders store={store}>{children}</RenderWithProviders>
),
});

await waitFor(() => {
Expand All @@ -142,7 +164,7 @@ describe('useProfileSyncing', () => {
() => useDeleteAccountSyncingDataFromUserStorage(),
{
wrapper: ({ children }) => (
<Provider store={store}>{children}</Provider>
<RenderWithProviders store={store}>{children}</RenderWithProviders>
),
},
);
Expand Down

0 comments on commit e50d6f9

Please sign in to comment.