【问题标题】:Jasmine tests fail randomlyJasmine 测试随机失败
【发布时间】:2020-03-13 16:25:55
【问题描述】:

我在竹子版本中运行我的茉莉花测试时遇到了一个奇怪的问题。测试随机失败并出现以下错误:

Failed: can't convert undefined to object build   18-Nov-2019
03:08:56      ./node_modules/@angular/core/fesm5/core.js/</ReflectionCapabilities.prototype._ownPropMetadata@http://localhost:9876/_karma_webpack_/vendor.js:56242:13
build 18-Nov-2019
03:08:56      ./node_modules/@angular/core/fesm5/core.js/</ReflectionCapabilities.prototype.propMetadata@http://localhost:9876/_karma_webpack_/vendor.js:56265:31
build 18-Nov-2019
03:08:56      ./node_modules/@angular/core/fesm5/core.js/</ReflectionCapabilities.prototype.propMetadata@http://localhost:9876/_karma_webpack_/vendor.js:56260:40
build 18-Nov-2019
03:08:56      ./node_modules/@angular/platform-browser-dynamic/fesm5/platform-browser-dynamic.js/JitReflector.prototype.propMetadata@http://localhost:9876/_karma_webpack_/vendor.js:117510:16
build 18-Nov-2019
03:08:56      ./node_modules/@angular/compiler/fesm5/compiler.js/DirectiveResolver.prototype.resolve@http://localhost:9876/_karma_webpack_/vendor.js:32740:40
build 18-Nov-2019
03:08:56      ./node_modules/@angular/compiler/fesm5/testing.js/MockDirectiveResolver.prototype.resolve@http://localhost:9876/_karma_webpack_/vendor.js:54975:46
build 18-Nov-2019
03:08:56      ./node_modules/@angular/compiler/fesm5/compiler.js/CompileMetadataResolver.prototype.getNonNormalizedDirectiveMetadata@http://localhost:9876/_karma_webpack_/vendor.js:40491:23
build 18-Nov-2019
03:08:56      ./node_modules/@angular/compiler/fesm5/compiler.js/CompileMetadataResolver.prototype.loadDirectiveMetadata@http://localhost:9876/_karma_webpack_/vendor.js:40422:18
build 18-Nov-2019
03:08:56      ./node_modules/@angular/compiler/fesm5/compiler.js/JitCompiler.prototype._loadModules/</<@http://localhost:9876/_karma_webpack_/vendor.js:53988:31
build 18-Nov-2019
03:08:56      ./node_modules/@angular/compiler/fesm5/compiler.js/JitCompiler.prototype._loadModules/<@http://localhost:9876/_karma_webpack_/vendor.js:53987:13
build 18-Nov-2019
03:08:56      ./node_modules/@angular/compiler/fesm5/compiler.js/JitCompiler.prototype._loadModules@http://localhost:9876/_karma_webpack_/vendor.js:53984:9
build 18-Nov-2019
03:08:56      ./node_modules/@angular/compiler/fesm5/compiler.js/JitCompiler.prototype._compileModuleAndAllComponents@http://localhost:9876/_karma_webpack_/vendor.js:53969:31
build 18-Nov-2019
03:08:56      ./node_modules/@angular/compiler/fesm5/compiler.js/JitCompiler.prototype.compileModuleAndAllComponentsAsync@http://localhost:9876/_karma_webpack_/vendor.js:53928:32
build 18-Nov-2019
03:08:56      ./node_modules/@angular/platform-browser-dynamic/fesm5/platform-browser-dynamic.js/CompilerImpl.prototype.compileModuleAndAllComponentsAsync@http://localhost:9876/_karma_webpack_

经过几次重新运行测试开始通过。我无法确定根本原因。每次运行都未通过不同的测试。

【问题讨论】:

    标签: javascript angular typescript jasmine karma-jasmine


    【解决方案1】:

    您的 Jasmine 测试之间似乎存在依赖关系。

    我建议使用“focused it”来检查您的测试用例,并在其他测试没有在他之前运行时找到那些失败的测试用例。特别是这意味着您遍历测试用例,将“it”更改为“fit”,并检查它是否通过了只有一个测试运行。如果它通过了,则将“适合”更改回“它”,然后继续进行下一个。如果你发现一个失败的,你可以找出它的依赖关系并修复它。

    除了“fdescribe”之外,“describe”还有另一种写法。使用“fdescribe”仅运行该描述中的测试。这样你就可以找到“describe”-s之间的依赖关系了。

    更多关于“fit”和“fdescribe”的信息在这里:https://jasmine.github.io/api/3.0/global

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-31
      • 2021-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-15
      相关资源
      最近更新 更多