【发布时间】:2022-06-16 04:00:32
【问题描述】:
我最近开始在我的 create-react-app 应用程序中使用 azure 活动目录,当我尝试运行测试时遇到了这个错误。
BrowserAuthError: crypto_nonexistent: The crypto object or function is not available. Detail:Browser crypto or msCrypto object not available.
25 | import { NavigationProvider } from './contexts/index';
26 |
> 27 | export const msalInstance = new PublicClientApplication(msalConfig);
我找到了React jest and MSAL getting BrowserAuthError : crypto,这似乎是我的确切问题,但是我的笑话配置在我的 package.json 中并且看起来像这样:
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx}",
"!src/**/*.{config,stories}.js",
"!src/**/index.js"
],
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 80
}
}
},
在阅读了一些文档之后,我仍然很难弄清楚如何在我的 package.json 中将 crypto 添加到我的 jest 配置中。我还尝试将我的 jest 配置迁移到独立的 jest.config.js 并将我的测试脚本切换到 react-scripts test -- --config jest.config.js 但无法让它工作。
解决此问题的最佳方法是什么?我假设这是一个简单的修复,但我只是无法为任一版本的配置找出正确的语法。谢谢!
【问题讨论】:
标签: reactjs jestjs azure-active-directory