angular5 - 角度 5 单元测试 - 出现错误“无法读取 null 的属性 offsetHeight”
问题描述
当我对我的应用程序进行单元测试时,它显示以下错误
TypeError: Cannot read property 'offsetHeight' of null
在我的应用程序中,我使用下面的代码来获取 div 元素的高度
totalHeight= (document.getElementById("rcyc-page-header") as HTMLElement).offsetHeight +
(document.querySelector("nav.menu-wrapper.brand-nav-wrapper") as HTMLElement).offsetHeight;
当我打印变量“totalheight”的值时,它显示正确,那么为什么会显示此错误?
解决方案
推荐阅读
- sumo - 我可以通过traci获取SUMO中车辆的蓝牙数据吗?
- php - 如何在 PHP 中使用 PLAID 实现 Stripe ACH
- sql - SQL错误:过多coalesce导致BCD溢出
- ios - iOS ARKit ARFaceAnchor 导出到具有实际面部大小的 3D 模型文件?
- javascript - 根据开始值和结束值对数字数组进行排序
- python - python检查在不同类中启动的线程
- c - 如何从给定 LLVM IR 的源代码中获取变量的所有行号?
- strapi - 如何使用 GraphQL 作为经过身份验证的用户查询 Strapi 后端?
- python - 如何修补参数化夹具内的功能?
- firebase - 图像太大时如何缩小图像?