Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

testing library react hooks

import { renderHook, act } from '@testing-library/react-hooks'
import useCounter from './useCounter'

test('should increment counter', () => {
  const { result } = renderHook(() => useCounter())

  act(() => {
    result.current.increment()
  })

  expect(result.current.count).toBe(1)
})
Comment

react testing library for hooks

npm install --save-dev @testing-library/react-hooks
Comment

react testing library for hooks

import { useState, useCallback } from 'react'

function useCounter() {
  const [count, setCount] = useState(0)

  const increment = useCallback(() => setCount((x) => x + 1), [])

  return { count, increment }
}

export default useCounter
Comment

PREVIOUS NEXT
Code Example
Javascript :: discord.js setactivity 
Javascript :: react context 
Javascript :: primitive and non primitive data types in javascript 
Javascript :: check time javascript 
Javascript :: how to stop re rendering in react 
Javascript :: get current html file name javascript 
Javascript :: nextjs open browser automatically 
Javascript :: start pm2 node process with flags 
Javascript :: custom timestamp name mongoose 
Javascript :: jquery get img src 
Javascript :: mapdispatchtoprops 
Javascript :: jQuery get background image url of element 
Javascript :: onload of modal jquery function 
Javascript :: how to remove property of object in javascript without delete 
Javascript :: http get response body node js 
Javascript :: new line in javascript alert 
Javascript :: how get height elemnt with that margin in js 
Javascript :: passportjs serializeuser 
Javascript :: prime number in javascript 
Javascript :: convert a string into an integer 
Javascript :: js caps first letter 
Javascript :: how to get type of variable in javascript 
Javascript :: cypress store cookies 
Javascript :: set datatable with jquery success return value 
Javascript :: middleware 
Javascript :: replace all with regex 
Javascript :: react 360 
Javascript :: ubuntu internet speed booster 
Javascript :: Javascript load at Window loading time 
Javascript :: array put value in index 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =