如何在Jasmine中加入HBS模板?
问题描述:
我正在用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文件。由于模板中类似的动态值(这里是名称),我无法使用静态夹具方法。
答
我发现下面的例子通过链接,我在这个问题给出的,而夹具用于HTML
loadFixtures('myfixture.html');
// Run test
some.methodToTest();
// Expect that the methodToTest has modified the content in the div
expect($('#fixtureId')).to...;
我找到答案了HBS也和其计算方法如下: -
- ,而不是加载
myfixture.html
的,我装我HBS file
。 - 此外,var t = readFixtures('myFixture.hbs')也可以做到这一点。
- 另一种使用方法
Handlebars.compile('myFixture.hbs')