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 :: set dynamic route in link react js 
Javascript :: simple kick command discord.js v12 
Javascript :: jquery click on data attribute 
Javascript :: array length javascript 
Javascript :: check css property jquery 
Javascript :: default selected radio button angular material 
Javascript :: random id generator javascript 
Javascript :: moment js get date 1 month 
Javascript :: javascript number format 
Javascript :: run on load js 
Javascript :: how to read xml element in xml2js 
Javascript :: how to get the div value in jquery 
Javascript :: connecting nodejs using mongoose 
Javascript :: add new items in a select input using js 
Javascript :: how to delete node_modules 
Javascript :: Use Destructuring Assignment with the Rest Operator to Reassign Array Elements 
Javascript :: replace many chracters js 
Javascript :: object traversal javascript 
Javascript :: react tostify 
Javascript :: angular library run tests 
Javascript :: window.scrollto(0 0) not working 
Javascript :: math .round 
Javascript :: wait for element to load javascript 
Javascript :: textalignvertical not working in ios react native 
Javascript :: string to jspn js 
Javascript :: javascript get child element by parent id 
Javascript :: js double exclamation mark 
Javascript :: js object using variable as key 
Javascript :: $q.platform.is.mobile 
Javascript :: javascript random number up to including 2 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =