美文网首页
单元测试踩坑

单元测试踩坑

作者: 玩问 | 来源:发表于2021-08-10 15:35 被阅读0次

问题1

描述:使用react-test-renderer渲染组件,生成快照时报错Unable to find node on an unmounted component.

解决: react-test-renderer版本降级,我之前用的是17.0.0,降级到16.14.0

yarn upgrade react-test-renderer@16.14.0

问题2

描述:测试antd组件时,报错useLayoutEffect does nothing on the server。

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://fb.me/react-uselayouteffect-ssr for common fixes.
          in CSSMotion
          in LoadingIcon
          in button
          in Context.Consumer
          in Wave
          in Button
          in ExportButton

解决:

jest.mock('react', () => ({
    ...jest.requireActual('react'),
    useLayoutEffect: jest.requireActual('react').useEffect,
}));

踩坑是一个持续的过程,所以这篇文章会不断更新,将我做单元测试遇到的所有问题进行汇总。

相关文章

  • 记一次SpringBoot 单测踩坑记录

    单元测试踩坑记录: 使用Mockito.when() 时mock总是不生效 (1)问题when(commonSer...

  • 单元测试踩坑

    问题1 描述:使用react-test-renderer渲染组件,生成快照时报错Unable to find no...

  • 单元测试踩坑指南

    实习期间做单元测试,一开始都靠往数据库硬塞数据,后来发现这样做就算本地能通过,在线上通不过,故开始学习,发现遇到的...

  • PowerMock踩坑指南

    单元测试踩过无数的坑,都源于源代码写的不好,但是如何在不修改源代码的同时把单元测试写好,是我这个实习生应该摸索的,...

  • JavaScrip-StepPitGuide《JavaScrip

    《JavaScript踩坑指南》JavaScrip-StepPitGuide? 《JavaScript踩坑指南》 ...

  • 算法踩坑6-二叉搜索树排序

    背景 接上面五篇文章算法踩坑-快速排序 算法踩坑2-插入排序 算法踩坑3-堆排序 算法踩坑4-冒泡排序 ...

  • 算法踩坑5-归并排序

    背景 接上面四篇文章算法踩坑-快速排序 算法踩坑2-插入排序 算法踩坑3-堆排序 算法踩坑4-冒泡排序 来...

  • D1094:踩坑的价值最大化

    是人就会踩坑,不踩坑理论上就不属于人类,踩坑是人之常情,能回头站在坑边反思,才是对踩过的的坑价值最大化的体现,要不...

  • 交互设计师所要避免的几个坑

    前言 工作中难免会踩到几个坑,即使现在不踩以后还会踩,只有踩过才会深刻记住,踩过说明爱过!但是踩过的坑必须把坑填满...

  • 指南与踩坑:Python 单元测试

    本文试图总结编写单元测试的流程,以及自己在写单元测试时踩到的一些坑。如有遗漏,纯属必然,欢迎补充。 目录概览: 编...

网友评论

      本文标题:单元测试踩坑

      本文链接:https://www.haomeiwen.com/subject/dazxbltx.html