【发布时间】:2017-11-16 13:04:16
【问题描述】:
我正在尝试对使用自定义管道的组件进行单元测试。我想为我的测试提供transform 方法的假实现。
我发现override组件、模块、管道等是可能的,但是我看不出如何覆盖组件的行为(实现)。
我尝试为我提供自定义类作为管道的替代品,但它不起作用:
TestBed
.configureTestingModule({declarations: [MyPipe]})
.overridePipe(MDatePipe, {set: MyFakePipe})
我在 SO How to mock Pipe when testing Component 上发现了类似的问题,但建议的解决方案是创建完整的新管道并将其提供给测试模块的 declarations,这在我看来有点太多了。
如果overridePipe 不允许我覆盖transform 实现,是否可以获得创建的MyPipe 类和spyOn 的实例?
var pipe = TestBed.get(MyPipe);
也没有用。
【问题讨论】:
标签: javascript angular unit-testing