测试无法在resetFakeAsyncZone读取未定义的属性'assertPresent' [英] Testing | Cannot read property 'assertPresent' of undefined at resetFakeAsyncZone

查看:134
本文介绍了测试无法在resetFakeAsyncZone读取未定义的属性'assertPresent'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对业力v1.4有问题.测试框架. 我所有的单元测试现在都失败,错误为Cannot read property 'assertPresent' of undefined at resetFakeAsyncZone

I have a problem with karma v1.4. testing framework. All my unit tests are now failing with error Cannot read property 'assertPresent' of undefined at resetFakeAsyncZone

我已经在寻找解决方案并对其进行了测试,但不幸的是,没有任何帮助. 解决方案建议我应该更改test.js文件中的导入顺序.我已经做到了.

I've already searched for solutions and tested them, but unfortunately none helped. The solutions suggests that I should change the order of imports in my test.js file. I've done that.

这是我正在使用的建议顺序,但仍然失败:

This is the suggested order I am using, but it still fails:

import 'zone.js/dist/zone.js'; // 1st
import 'zone.js/dist/async-test'; // 2nd
import 'zone.js/dist/fake-async-test'; // 3rd
import 'zone.js/dist/long-stack-trace-zone'; // 4th
import 'zone.js/dist/sync-test'; // 5th
import 'zone.js/dist/proxy.js'; // 6th
import 'zone.js/dist/jasmine-patch'; // 7th

PS:我正在使用VS Code,它现在在保存文件时自动对导入进行排序,从而更改了我的自定义导入顺序,在这种情况下,这非常烦人.我不知道如何仅针对特定文件禁用它,因此我必须在记事本中编辑test.js文件.

PS: I am using VS Code, which now automatically sorts imports upon file save and thus changes my custom order of imports, which is super annoying in this case. I do not know how to disable it for specific file only, so I have to edit my test.js file in Notepad.

推荐答案

使用哪个版本的zone.js?

在新版本的zone.js中,无需分别加载每个 test lib .

In the newer version of zone.js, there is no need to load each test lib separately.

将以下内容放在test.ts的顶部.

Place the following at the top of test.ts.

import 'zone.js/dist/zone-testing';

注意:重要的是,此导入要早于其他任何导入!

Note: It is important that this import is before any other imports!

这篇关于测试无法在resetFakeAsyncZone读取未定义的属性'assertPresent'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆