Angular2 RC4:覆盖指令
Angular2 RC4: overrideDirective
我刚刚将 RC3 更新为 RC4,现在我在测试中遇到此错误:
Error: overrideDirective is not supported in this implementation of TestComponentBuilder
在 TestComponentBuilder
里面 @angular/core@2.0.0-rc.4/testing/test_component_builder.js
我可以看到这个方法的声明
TestComponentBuilder.prototype.overrideDirective = function(componentType, from, to) {
throw new Error('overrideDirective is not supported in this implementation of TestComponentBuilder.');
};
所以现在的问题是:如何覆盖指令?
好的,看来他们故意删除了该功能,而没有用 this issue
中所述的其他内容替换它
所以我找到的唯一解决办法是使用一个奇怪的 OverridingTestComponentBuilder
突然出现在 compiler/testing
.
这并不理想,因为从 RC4 TestComponentBuilder
应该从 @angular/core/testing
导入,但这是一个临时修复,等待他们解决这个问题。
导入 class 后,您可以像使用 TestComponentBuilder
一样使用它
import { OverridingTestComponentBuilder } from '@angular/compiler/testing'
beforeEach(inject([OverridingTestComponentBuilder], _tcb => {
tcb = _tcb
}));
并且所有覆盖*方法应该都能很好地工作。
默认的 Angular 测试提供商应该默认为您提供 TestComponentBuilder 类型的 OverridingTestComponentBuilder 实现。你如何设置你的测试? (例如 setBaseTestProviders?使用 Angular 提供的列表应该可以解决您的问题。这是一个示例:https://github.com/juliemr/ng2-test-seed/blob/master/karma-test-shim.js#L84
我刚刚将 RC3 更新为 RC4,现在我在测试中遇到此错误:
Error: overrideDirective is not supported in this implementation of TestComponentBuilder
在 TestComponentBuilder
里面 @angular/core@2.0.0-rc.4/testing/test_component_builder.js
我可以看到这个方法的声明
TestComponentBuilder.prototype.overrideDirective = function(componentType, from, to) {
throw new Error('overrideDirective is not supported in this implementation of TestComponentBuilder.');
};
所以现在的问题是:如何覆盖指令?
好的,看来他们故意删除了该功能,而没有用 this issue
中所述的其他内容替换它所以我找到的唯一解决办法是使用一个奇怪的 OverridingTestComponentBuilder
突然出现在 compiler/testing
.
这并不理想,因为从 RC4 TestComponentBuilder
应该从 @angular/core/testing
导入,但这是一个临时修复,等待他们解决这个问题。
导入 class 后,您可以像使用 TestComponentBuilder
import { OverridingTestComponentBuilder } from '@angular/compiler/testing'
beforeEach(inject([OverridingTestComponentBuilder], _tcb => {
tcb = _tcb
}));
并且所有覆盖*方法应该都能很好地工作。
默认的 Angular 测试提供商应该默认为您提供 TestComponentBuilder 类型的 OverridingTestComponentBuilder 实现。你如何设置你的测试? (例如 setBaseTestProviders?使用 Angular 提供的列表应该可以解决您的问题。这是一个示例:https://github.com/juliemr/ng2-test-seed/blob/master/karma-test-shim.js#L84