Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 6 of 7 · Testing React Applications
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?