Question

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.

Was it helpful?

Solution

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')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top