Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们正在使用 JS-Data、JS-Data-Http 与 angular2 应用程序中的 Service 进行交互。当我们进行单元测试时遇到问题。谁能解释一下如何为 JS-Data-Http 创建模拟对象?
单元测试不应该需要外部资源,例如 REST 服务。要模拟 findAll 的响应,您可以执行以下代码。确保您已包含 JSData 模拟,否则它将发出 HTTP 请求,您将看到由于意外请求而导致的错误。
DS.expectFindAll('task') .respond([{"id": 1, "title": "Task 1"},{"id": 2, "title": "Task 2"}]);