zoukankan      html  css  js  c++  java
  • [Javascript] Wrap fireEvent with fireEventAsync

    The idea is wrap a object with all its function methods and add some additional handling into a new object.

    For example, we have a object 'fireEvent':

    import {fireEvent, wait} from 'dom-testing-library'
    async function render() {
      fireEvent.click(handleClick)
      await wait()
    }

    What we want to achieve is:

    fireEventAsync.click(handleClick);
    import {fireEvent, wait} from 'dom-testing-library'
    
    const fireEventAsync = {}
    
    Object.entries(fireEvent).reduce((obj, [key, val]) => {
      obj[key] = async (...args) => {
         const ret = val(...args)
         await wait()
         return ret
      }
    
      return obj
    }, fireEventAsync)
    
    export {fireEventAsync}    
  • 相关阅读:
    函数
    registry搭建及镜像管理-harbor
    用户输入和while 循环
    dockerfile
    字典,set
    if 语句
    alpine操作
    循环:列表,元组
    列表
    docker跨主机通信-overlay
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10100222.html
Copyright © 2011-2022 走看看