从简单搜索到单页应用:Angular与Rails的深度整合
1. 单元测试与错误处理
在进行单元测试时,我们使用了 Testdouble.js 来模拟全局对象。例如,在 CustomerSearchComponent 的测试中,我们模拟了 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!"));
});
});
});
这里使用 td.verify 来验证
超级会员免费看
订阅专栏 解锁全文
2553

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



