Skip to content

Commit

Permalink
use renderHookWithProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Mar 6, 2024
1 parent 928c60b commit 02a0c73
Showing 1 changed file with 22 additions and 40 deletions.
62 changes: 22 additions & 40 deletions ui/hooks/usePolling.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';
import { renderHook, cleanup } from '@testing-library/react-hooks';
import { Provider } from 'react-redux';
import configureStore from '../store/store';
import { cleanup } from '@testing-library/react-hooks';
import { renderHookWithProvider } from '../../test/lib/render-helpers';
import usePolling from './usePolling';

describe('usePolling', () => {
Expand All @@ -17,31 +15,22 @@ describe('usePolling', () => {
metamask: {},
};

const wrapper = ({ children }) => (
<>
<Provider store={configureStore(mockState)}>{children}</Provider>
</>
);

renderHook(
() => {
usePolling({
callback: (pollingToken) => {
expect(mockStart).toHaveBeenCalledWith(networkClientId, options);
expect(pollingToken).toBeDefined();
done();
return (_pollingToken) => {
// noop
};
},
startPollingByNetworkClientId: mockStart,
stopPollingByPollingToken: mockStop,
networkClientId,
options,
});
},
{ wrapper },
);
renderHookWithProvider(() => {
usePolling({
callback: (pollingToken) => {
expect(mockStart).toHaveBeenCalledWith(networkClientId, options);
expect(pollingToken).toBeDefined();
done();
return (_pollingToken) => {
// noop
};
},
startPollingByNetworkClientId: mockStart,
stopPollingByPollingToken: mockStop,
networkClientId,
options,
});
}, mockState);
});
// eslint-disable-next-line jest/no-done-callback
it('calls the cleanup function with the correct pollingToken when unmounted', (done) => {
Expand All @@ -55,14 +44,8 @@ describe('usePolling', () => {
metamask: {},
};

const wrapper = ({ children }) => (
<>
<Provider store={configureStore(mockState)}>{children}</Provider>
</>
);

renderHook(
() => {
renderHookWithProvider(
() =>
usePolling({
callback: () => {
return (_pollingToken) => {
Expand All @@ -75,9 +58,8 @@ describe('usePolling', () => {
stopPollingByPollingToken: mockStop,
networkClientId,
options,
});
},
{ wrapper },
}),
mockState,
);
cleanup();
});
Expand Down

0 comments on commit 02a0c73

Please sign in to comment.