我正在使用带有 Office.js 的 React-fabric UI 来创建 Excel 插件。在 CDN 下用于在 index.html 文件中导入 office.js。
<script
src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"
type="text/javascript"
></script>
下面是我的 jest.config.json
{
"testEnvironment": "node",
"verbose": true,
"files": ["https://appsforoffice.microsoft.com/lib/1/hosted/office.js"],
"setupFilesAfterEnv": ["<rootDir>/setupTests.js"],
"moduleFileExtensions": ["js", "jsx", "json"],
"transform": {
"^.+\\.(t|j)s$": "babel-jest"
},
"moduleDirectories": ["node_modules", "<rootDir>/app/src"],
"testPathIgnorePatterns": [
"Office",
"node_modules",
"<rootDir>/app/src/styles",
"<rootDir>/app/images"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/app/__mocks__/fileMock.js",
"\\.(css|sass|scss)$": "<rootDir>/app/__mocks__/styleMock.js",
"office-ui-fabric-react/lib/(.*)$": "office-ui-fabric-react/lib-commonjs/$1",
"alias": {
"^components(.*)$": "<rootDir>/app/src/components/$1",
"^utils/(.*)$": "<rootDir>/app/src/utils/$1",
"^styles/(.*)$": "<rootDir>/app/src/styles/$1",
"^@[/](.+)": "<rootDir>/app/src"
}
},
"testMatch": ["**/__tests__/**/*.js?(x)"]
}
我的测试用例失败并出现以下错误:
ReferenceError: Office 未定义
请帮助解决此问题,因为尝试了多种方法来解决此问题,但没有运气。