【问题标题】:Unit testing the viewmodels and mocking the dependencies对视图模型进行单元测试并模拟依赖项
【发布时间】:2013-08-20 19:31:39
【问题描述】:

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

我正在尝试通过传递一个模拟服务来测试我的虚拟机,比如说......

视图模型:

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

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

谢谢

【问题讨论】:

    标签: knockout.js durandal hottowel


    【解决方案1】:

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

    使用 Jasmine,您将拥有一个执行所有 ViewModel 的 HTML 页面。它允许您模拟函数。我链接到的页面包含对 Jasmine 可以做什么的完整描述。

    例子:

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

    【讨论】:

    • 我会试一试,但它看起来像我需要的。谢谢
    猜你喜欢
    • 1970-01-01
    • 2023-03-13
    • 2016-02-19
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 2013-07-07
    • 1970-01-01
    • 2017-09-25
    相关资源
    最近更新 更多