Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing backbone.js不';t使用konacha渲染视图_Unit Testing_Backbone.js_Coffeescript_Mocha.js_Konacha - Fatal编程技术网

Unit testing backbone.js不';t使用konacha渲染视图

Unit testing backbone.js不';t使用konacha渲染视图,unit-testing,backbone.js,coffeescript,mocha.js,konacha,Unit Testing,Backbone.js,Coffeescript,Mocha.js,Konacha,我想用konacha为我的backbone.js应用程序做一些DOM测试。我在下面读了一些关于科纳查的文章 这些条目表明我应该创建一个视图并将其放入页面对象中,如下所示 #= require spec_helper describe "MyApp.Views.Relationships", -> beforeEach -> @view = new MyApp.Views.Relationships() @page.html(@view.el) console.

我想用konacha为我的backbone.js应用程序做一些DOM测试。我在下面读了一些关于科纳查的文章

这些条目表明我应该创建一个视图并将其放入页面对象中,如下所示

#= require spec_helper
describe "MyApp.Views.Relationships", ->
  beforeEach ->
  @view = new MyApp.Views.Relationships()
  @page.html(@view.el)
  console.log @view.el
问题: 但是上面代码中的console.log为@view.el显示“undefined”,尽管这些代码在实践中运行良好

如果有人能帮助我,我真的很感激

这里是一些感兴趣的代码

spec_helper.js.coffee
#= require application
#= require_tree ./support

mocha.ui('bdd')
mocha.ignoreLeaks()

beforeEach ->
  @page = $("#konacha")
  @sandbox = sinon.sandbox.create()

afterEach ->
  @sandbox.restore()
 

 

relationships.jst.eco
 

profile.html.erb(已提取)
#剪断#
#剪断#
$(函数(){
新建MyApp.Views.Relationships()
});
我想用这些代码处理像twitter一样的follow按钮


提前感谢。

在规范中包含视图所需的模板。比如:

#= require spec_helper
#= require templates/users/relationships

describe "MyApp.Views.Relationships", ->
    beforeEach ->
    @view = new MyApp.Views.Relationships()
    @page.html(@view.el)
    console.log @view.el
或者模板所在的位置

模板可能仍然未定义。如果是这种情况,则可能是在加载模板之前加载了应用程序。因此,如果是这种情况,您也可以在spec_助手中删除require应用程序,只在每个spec中包含您正在测试的位

relationships.jst.eco
<button class="btn" disabled="disabled"><%- @img %></button>
profile.html.erb(extracted)
   #snip#
            <% if signed_in? and @user != current_user %>
              <div id="relation-form" class="action-button"></div>
            <% end %>
   #snip#
    <script type="text/template" id="loading-image">
      <%= image_tag('ajax-loader.gif') %>
    </script>
    <script type="text/javascript">
      $(function () {
        new MyApp.Views.Relationships()
      });
    </script>
#= require spec_helper
#= require templates/users/relationships

describe "MyApp.Views.Relationships", ->
    beforeEach ->
    @view = new MyApp.Views.Relationships()
    @page.html(@view.el)
    console.log @view.el