我使用默认的Aurelia的sceleton esnext更新到上一个版本。我已将此行添加到应用程序(文档中的示例。自定义导航管道)
config.addPipelineStep('authorize', AuthorizeStep);
在这之后,我发现运行"吞咽测试"时出错
Chrome 52.0.2743 (Linux 0.0.0) the App module contains a router property FAILED
TypeError: config.addPipelineStep is not a function
测试
it('contains a router property', () => {
expect(sut.router).toBeDefined();
});
测试进行得很顺利。
我刚刚遇到这个问题。要修复,您只需要在RouterStub:中添加一个空方法
class RouterStub {
configure(handler) {
handler(this);
}
map(routes) {
this.routes = routes;
}
addPipelineStep(stepName, stepClass) {
}
}
然后在你的测试中:
describe('the App module', () => {
var app;
var mockedRouter;
beforeEach(() => {
mockedRouter = new RouterStub();
app = new App();
app.configureRouter(mockedRouter, mockedRouter);
});
it('contains a router property', () => {
expect(app.router).toBeDefined();
});
});
如果你试图测试管道步骤,你需要模拟路由器本身并测试实际逻辑,但如果你只想运行测试(即定义测试、检查路由器标题等),这将起作用。