Ionic 无法在离子中模拟电容器插件

erhoui1w  于 2022-12-09  发布在  Ionic
关注(0)|答案(1)|浏览(255)

我的tsconfig.spec.json

"paths": {
   "@test/*": ["tests/*"],
   "@capacitor/*": ["tests/src/mocks/capacitor/*"]
}

我在tests/src/mocks/capacitor/camera.ts下有一个Camera.ts文件,它实现了来自电容器的CameraPlugin。
不过,当做任何测试时,我会收到“未在Web上实现”

An error was thrown in afterAll
  Unhandled promise rejection: Error: Not implemented on web.
  error properties: Object({ code: 'UNIMPLEMENTED' })

有人知道我错过了什么吗?谢谢!

eiee3dmh

eiee3dmh1#

是否在正确的位置声明了“paths”?它应该在“compilerOptions”中设置
下面是一个tsconfig.spec.json文件示例。

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/spec",
    "types": [
      "jasmine",
      "node"
    ],
    "paths": {
      "@capacitor/*": ["__mocks__/@capacitor/*"],
      "@capacitor-community/*":["__mocks__/@capacitor-community/*"]
    }
  },
  "files": [
    "src/test.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.spec.ts",
    "src/**/*.d.ts"
  ]
}

相关问题