Angular TypeError:无法读取属性';原型&x27;使用玩笑的未定义的

Angular TypeError:无法读取属性';原型&x27;使用玩笑的未定义的,angular,typescript,unit-testing,jestjs,Angular,Typescript,Unit Testing,Jestjs,我正在使用jest框架对我的Angular应用程序进行单元测试。我觉得test.ts文件和zone.js有问题 我正在获取错误堆栈跟踪 TypeError: Cannot read property 'prototype' of undefined 3 | import { getTestBed } from '@angular/core/testing'; 4 | import 'zone.js/dist/zone-testing'; > 5 | imp

我正在使用jest框架对我的Angular应用程序进行单元测试。我觉得test.ts文件和zone.js有问题

我正在获取错误堆栈跟踪

TypeError: Cannot read property 'prototype' of undefined

      3 | import { getTestBed } from '@angular/core/testing';
      4 | import 'zone.js/dist/zone-testing';
    > 5 | import {
        | ^
      6 |   BrowserDynamicTestingModule,
      7 |   platformBrowserDynamicTesting
      8 | } from '@angular/platform-browser-dynamic/testing';

      at __extends (node_modules/zone.js/dist/zone-testing.js:394:73)
      at node_modules/zone.js/dist/zone-testing.js:530:9
      at node_modules/zone.js/dist/zone-testing.js:619:7
      at node_modules/zone.js/dist/zone-testing.js:620:3
      at Object.<anonymous>.NEWLINE (node_modules/zone.js/dist/zone-testing.js:9:65)
      at Object.<anonymous> (node_modules/zone.js/dist/zone-testing.js:12:2)
      at Object.<anonymous> (src/test.ts:5:1
我使用了
编译器选项

“esModuleInterop”:true,
“模块”:“es2015”,

正如我所说的,我正在寻找一种方法,用最少的代码更改来解决这个问题。感谢您的帮助。

如果您已经完全迁移到Jest,您可以删除test.ts,因为您不再使用Jasmine和Karma,因此不再需要它。你可以阅读

另外,请确保从tsconfig.spec.ts中删除其引用

如果出于某种原因,您需要保留它,您可以在Jest配置中忽略test.ts文件,因为默认情况下Jest将测试所有以spec.ts/js和test.ts/js结尾的文件

**Default configuration:** 
testMatch: [ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ]

**Change to:**
testMatch: [ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.spec).[jt]s?(x)" ]

您可以阅读有关配置Jest的更多信息

感谢您提供的解决方案。我以前也试过。然后它产生了以下错误<代码>类型脚本诊断(使用“[jest config].globals.ts jest.diagnostics”选项自定义):错误TS6053:File“…/Sample-Login-App\u jest/src/test.ts”未找到。经过一些修改后,我看到tsconfig.spec.ts文件在其文件数组中包含test.ts文件。在我移除它后,测试工作正常。谢谢你,我会用这个更新答案的。可能会帮助其他人。:)