使用fluentui组件运行测试用例时出错



我正试图在reactjs项目中运行一些简单的测试。当被测试的组件导入了"@fluentui/areact"或"@fluntui/areact-northstar"时,我遇到了以下错误-

Test suite failed to run
TypeError: Class extends value undefined is not a constructor or null
1 | import { Provider } from 'react-redux';
> 2 | import { registerIcons } from '@fluentui/react';
| ^
3 |
at Object.__extends (node_modules/@fluentui/utilities/node_modules/tslib/tslib.js:70:19)
at node_modules/@fluentui/utilities/src/BaseComponent.ts:20:81

有人知道在fluentui库的情况下是什么导致了这个错误,以及如何消除它吗?

试图将依赖React的模块导入测试是行不通的,因为当它运行时,测试套件对React一无所知。它只是在Node上运行。registerIcons调用的任何内容都不在作用域中,因此它会失败。

您可以使用React测试库来提供帮助,例如Enzyme,它可以使用Jest或Mocha进行配置,或者Storybook,它是一个完整的UI开发工具。

最新更新