Allows for javascript template engines to be used within _SpecRunner.html
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
vendor
.gitignore
.jshintrc
.npmignore
.travis.yml
Gruntfile.js
LICENSE
README.md
package.json
strider-custom.json

README.md

Handlebars/Underscore template for Jasmine unit tests

Build Status

Allows for javascript template engines to be used within jasmine

Installation

npm install grunt-template-jasmine-templates --save-dev

Template Options

templateOptions.vendor

Type: String or Array Options: path to, or globbing patterns Default: none

The vendor to use. Handlebarjs and Underscore are both pre-saved in the vendor folder

Sample usage

// Example configuration using a single requireJS config file
grunt.initConfig({
  jasmine: {
    templates: {
      src: 'src/**/*.js',
      options: {
        specs: 'spec/*Spec.js',
        host: 'http://127.0.0.1:8000/',
        template: require('grunt-template-jasmine-templates'),
        templateOptions: {
          vendor: 'vendor/**/*.js',
          template: 'src/**/*.tmpl'
        }
      }
    }
  }
});

Note that you would need grunt-contrib-connect

Your *Spec file could look something like this:

describe("Handlebars templating", function() {

  // If you're trying to use a template named handlebars.tmpl,
  // it will be accessible via its id handlebars_tmpl
  var template = document.getElementById("handlebars_tmpl").innerHTML;

  it("has access to the template", function(){
    var compiledTemplate = Handlebars.compile(template);

    // Let's create some nodes from the template
    var el = document.createElement("div");
    el.innerHTML = compiledTemplate;
    el = el.children[0];

    // Let's now test these nodes
    expect(el.id).toBe("container_"+uid);
    expect(el.children[0].textContent).toBe("unique_"+uid);
  });

});