用酶测试 React 门户 [英] Testing React portals with enzyme
本文介绍了用酶测试 React 门户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我很难使用 React Fiber 的门户为模态组件编写测试.因为我的模态挂载到 <body/>
根上的 domNode 但由于该 domNode 不存在,所以测试失败.
提供一些代码,上下文:
index.html
<html lang="zh-cn"><头><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="%PUBLIC_URL%/manifest.json"><link rel="快捷图标" href="%PUBLIC_URL%/favicon.ico"><title>React 应用</title>头部><身体><noscript>您需要启用 JavaScript 才能运行此应用程序.</noscript><div id="modal-root"></div><div id="root"></div>