Interview question
How do you test hooks? Hooks को कैसे test करें?
Answer
import { renderHook, act } from '@testing-library/react';
import { useCounter } from './useCounter';
test('counter increments', () => {
const { result } = renderHook(() => useCounter());
act(() => { result.current.increment(); });
expect(result.current.count).toBe(1);
});renderHook से custom hooks को test कर सकते हैं।Was this answer clear?