本文介绍了如何修复beforeEachProviders(在RC4上弃用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚将Angular2从RC3升级到RC4 ......
Ive just upgraded Angular2 from RC3 to RC4 ...
import {
expect, it, iit, xit,
describe, ddescribe, xdescribe,
beforeEach, beforeEachProviders, withProviders,
async, inject
} from '@angular/core/testing';
在我的单元测试中,我有以下代码......
In my unit test I have the following code ...
beforeEachProviders(() => [
{provide: Router, useClass: MockRouter}
]);
这很好但是自从转到RC4后我在之前有一个弃用警告在beforeEachProviders之前
。
This works fine but since moving to RC4 I have a deprecation warning on beforeEachProviders
.
任何人都知道新的做事方式是什么?或者我应该从其他地方导入 beforeEachProviders
而不是'@ angular / core / testing'?
Anyone know what the new way of doing things is? Or should I import beforeEachProviders
from somewhere else instead of '@angular/core/testing'?
推荐答案
您需要从@ angular / core / testing导入addProviders。
You will need to import addProviders from @angular/core/testing.
而不是:
beforeEachProviders(() => [
{provide: Router, useClass: MockRouter}
]);
你想要这样做:
beforeEach(() => {
addProviders([
{provide: Router, useClass: MockRouter}
])
});
资料来源:
这篇关于如何修复beforeEachProviders(在RC4上弃用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!