await-async-task
Waits for async operations or timers to be completed. Useful for testing async operations and timers especially in React.js world. Helps to test Class components and hooks based components.
Installation
npm install await-async-task --save-devORyarn add await-async-task -D
Usage
- React component with async call in
componentDidMount
;;;;; const axiosMock = axios; Component { superprops; thisstate = status: "Loading" ; } async { try await axios; this catch e this } { return thisstatestatus; } ;
- React component with debounced action
;;; const debounceTime = 500; Component { superprops; thisstate = status: "Loading" ; } debounceMe = ; { return <div> <button onClick=thisdebounceMe>Fetch</button> <span>thisstatestatus</span> </div> } ;
- React component with
useEffect
hook and async call
;;;;; const axiosMock = axios; const MyComponent = { const status setStatus = ; ; return <span>status</span>;}; ;