2013-05-07 69 views
1

我正在用javascript构建客户端Web应用程序。为了构建模板,我使用了HandleBars.js模板,即.hbs文件。 我正在使用Jasmine框架编写JavaScript代码的规范。 但我坚持从规格中的源文件加载.hbs模板。如何在Jasmine中加入HBS模板?

使用Jasmine-Jquery(Link)插件我已经包含了静态html模板。

这是一个示例模板的一部分:

<li> 
    <div class="fixedText"> 
    <div class="middleItem">Name</div> 
    <div class="midItemValue" style = "margin-right: 0.6rem;"> 
     <input id = "textNewGroupName" type="text" style = "width : 300px;" maxlength="300" name="name" value="{{name}}"> 
    </div> 
    </div> 
</li> 

包括在HBS文件。由于模板中类似的动态值(这里是名称),我无法使用静态夹具方法。

回答

0

我发现下面的例子通过链接,我在这个问题给出的,而夹具用于HTML

loadFixtures('myfixture.html'); 

// Run test 
some.methodToTest(); 

// Expect that the methodToTest has modified the content in the div 
expect($('#fixtureId')).to...; 

我找到答案了HBS也和其计算方法如下: -

  1. ,而不是加载myfixture.html的,我装我HBS file
  2. 此外,var t = readFixtures('myFixture.hbs')也可以做到这一点。
  3. 另一种使用方法Handlebars.compile('myFixture.hbs')
相关问题