【发布时间】:2014-04-17 22:19:45
【问题描述】:
好的,我刚刚开始使用 Browserify,并且在编写我的 jasmine 测试时遇到了一些问题。基本上我有一个主干视图,其中包含嵌套视图,现在出于测试目的,我显然不想在这里测试嵌套视图,因为它正在使用自己的单元测试进行测试。我想要做的只是把它存根,检查它是否被正确调用
所以我有以下
nestedView = require('./nested_view.coffee')
module.exports = class MainView extends Backbone.View
initialize:(collection, attr)->
NestedView = if _.isUndefined(attr.Stub) then NestedView else attr.Stub
@nested_view = new NestedView()
然后在我的测试中:
it "Tests my nested view", ->
Stub = sinon.stub()
@mainview = new MainView(collection:@collection, {SV:Stub})
expect(Stub).toHaveBeenCalledOnce()
虽然这确实有效,但感觉有点讨厌,因为我不得不将代码添加到我的脚本中以运行测试。
有人知道更好的方法吗?
【问题讨论】:
-
嗯不确定我是否完全同意,尽管方法相似,但 requirejs imo 中有更好的方法。我也不确定答案是否能解决我的问题,即存根模型而不是元素。
标签: unit-testing jasmine sinon browserify