构建单页应用:从测试到路由配置
在软件开发过程中,测试和构建单页应用是非常重要的环节。本文将介绍如何进行单元测试,以及如何将一个简单的搜索界面转换为使用 Angular 路由器的单页应用。
单元测试的挑战与解决方案
在进行单元测试时,我们可能会遇到一些问题。例如,在测试 CustomerSearchComponent 时,使用 td.verify 来验证 window.alert 的调用。代码如下:
window = td.object(["alert"]);
describe("CustomerSearchComponent", function() {
describe("A search that fails on the back-end", function() {
beforeEach(function() {
td.when(window.alert()).thenReturn();
component = new CustomerSearchComponent(mockHttp);
});
it("alerts the user with the response message", function() {
component.search("pat");
td.verify(window.alert("There was an error!"));
});
});
});
这种方
超级会员免费看
订阅专栏 解锁全文
2万+

被折叠的 条评论
为什么被折叠?



