knockout.js - 单元测试 View 模型并模拟依赖项

标签 knockout.js durandal hottowel

我在 javascript 测试领域很新,我在我的 hottowel 应用程序中实现了一些问题。我在网上找到的大多数示例都没有测试 amd/require 并且关于 amd/require 的示例没有显示其他一些内容。

我正在尝试通过传递模拟服务来测试我的虚拟机,假设...

View 模型:

define(['services/dataService'], function (dataService) { function activate() { dataService.returnSomething(); } });

有人可以指出我如何实现这一目标的正确方向(最好是一个具体的例子)?任何测试框架和模拟库都可以。

谢谢

最佳答案

我目前正在使用 jasmine对我的 View 模型进行单元测试。

有了 Jasmine,你就有了一个 HTML 页面来执行你所有的 ViewModel。它允许您模拟功能。我链接到的页面包含对 Jasmine 可以做什么的完整描述。

例子:

var dataService = Require("services/dataService");
spyOn(dataService , 'returnSomething').andReturn("something");
// execute the system under test here
expect(dataService.returnSomething).toHaveBeenCalled();

关于knockout.js - 单元测试 View 模型并模拟依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18306410/

相关文章:

jquery - 为数据表选择最快的模板插件

ajax - 如何使 SPA SEO 可抓取?

javascript - 带有 Entity Framework : Extending entity's properties on the server, 的 Breeze JS 并在客户端上可用

javascript - Ajax 调用后在 Jquery .each 循环中应用 Knockout 绑定(bind)

javascript - knockout 可观察数组不会更新从数组中删除元素的 View

jquery - knockout.js 完成渲染所有元素后的成功回调

jquery - 我什么时候应该在 DurandalJS 中调用 jQueryUI 装饰函数?

asp.net-mvc-4 - 使用 SPA 架构验证AntiForgeryToken

ajax - Durandal : best way to pass data between ViewModels

css - 使用 Bootstrap 流体样式时,Durandal/Hot Towel 模板将 body max-width 设置为 1100px 的原因是什么?