如何在茉莉花中包含HBS模板? [英] How to include HBS template in Jasmine?

查看:153
本文介绍了如何在茉莉花中包含HBS模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



使用Jasmine-Jquery(链接)插件我已包括

这是样本模板的一部分:

 <李> 
< div class =fixedText>
< div class =middleItem>名称< / div>
< div class =midItemValuestyle =margin-right:0.6rem;>
< input id =textNewGroupNametype =textstyle =width:300px; maxlength =300name =namevalue ={{name}}>
< / div>
< / div>
< / li>

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

>通过我在问题中给出的链接找到了下面的示例,并且该夹具用于HTML

  loadFixtures( 'myfixture.html'); 

//运行测试
some.methodToTest();

//期望methodToTest修改了div
expect($('#fixtureId'))...的内容;

我也找到了HBS的答案,如下所示: -


  1. 我不是加载 myfixture.html ,而是加载了我的 HBS文件

  2. 此外,var t = readFixtures('myFixture.hbs')也可以做到这一点。

  3. 另一种方法是使用 Handlebars.compile('myFixture.hbs')


I am building a client-side web application in javascript. To build the templates I have used HandleBars.js templates, i.e. .hbs files. I am using Jasmine framework for writing the specs for the JavaScript Code. But I am stuck on loading the .hbs templates from the source files in the specs.

Using the Jasmine-Jquery (Link) plugin I have included the static html templates.

This is part of a sample template :

<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>

included in the hbs file. Because of the similar dynamic values (here name) in the templates I am unable to use the static fixture method.

解决方案

I found below example by the link that I given in the question, and that fixture is used for HTML

 loadFixtures('myfixture.html');

// Run test
some.methodToTest();

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

I found the answer for HBS also, and it is as follows:-

  1. Instead of loading myfixture.html, I loaded my HBS file.
  2. Moreover the same can be done by var t = readFixtures('myFixture.hbs').
  3. Another way be to use Handlebars.compile('myFixture.hbs')

这篇关于如何在茉莉花中包含HBS模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆