-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to test a custom hook using useWorker? #126
Labels
question
Further information is requested
Comments
More context, this is the hook I'm testing: const transactionTransformer = (input: InputType) => {
// expensive stuff happening here
return transactionList;
};
const useRecentTransactions = (params?: UseRecentTransactionsParams): UseRecentTransactionsType => {
const [transactions, setTransactions] = useState<Array<RecentTransaction>>([]);
const { lastMessage, connectionStatus } = useNetwork({ url: params?.url });
const [transactionWorker] = useWorker(transactionTransformer);
useEffect(() => {
const fetchTransactions = async () => {
if (connectionStatus === 'Open' && lastMessage !== undefined) {
const transactionList = await transactionWorker(lastMessage);
setTransactions((prevTransaction) =>
transactionList.concat(prevTransaction).slice(0, NUMBER_OF_TRANSACTIONS));
}
};
fetchTransactions();
}, [connectionStatus, lastMessage, setTransactions, transactionWorker]);
return {
transactions,
connectionStatus,
};
}; And the test file: it('should transform blocks and operations into transactions', async () => {
const { result } = renderHook(() => useRecentTransactions({ url: WEBSOCKET_URL }), {
wrapper: ({ children }) => <ContainerProvider>{children}</ContainerProvider>,
});
console.log(result.current);
}); |
It seems related to developit/jsdom-worker#16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been playing with useWorker, and it has been working on the browser.
I tried to create a test for a custom hook that is using the useWorker and got many errors.
I've tried to install
jsdom-worker
, but I keep receiving errors.I'm going to share the errors:
![image](https://user-images.githubusercontent.com/7468379/189768005-2fa102ba-c401-4852-888f-2a1885022c10.png)
☝️ with
jsdom-worker
![image](https://user-images.githubusercontent.com/7468379/189768073-8a986665-bbd6-4e2e-855f-acc5b3075954.png)
☝️ without `jsdom-worker`What kind of setup do I need to do to make it work using jest?
The text was updated successfully, but these errors were encountered: