johnbintz/jasmine-headless-webkit — Issue #88: Using hamljs templates with jasmine-headless-webkit?
Author: duncan-bayne
Created: 2011-12-05 07:24:15+00:00
State: open

I think I'm failing to understand something pretty fundamental here.

I'm trying to test some backbone.js views using Jasmine (via jasmine-headless-webkit). Everything is working well, except that my haml-js templates aren't accessible under test.

The following code in my view works fine:

render: =>
html = JST['views/avia_view_template']()
$(@el).html(html)

... but when it's run as part of a Jasmine spec I get the following failure:

ReferenceError: Can't find variable: JST in /home/duncan/avia/app/assets/javascripts/views/avia_view.js.coffee

I suspect I'm doing something wrong in `jasmine.yml`. I've explicitly included the template file it still fails:

src_files:
- "vendor/**/*.{js,coffee}"
- "lib/**/*.{js,coffee}"
- app/assets/javascripts/application.js
- app/assets/javascripts/avia.js
- app/assets/javascripts/jquery-1.6.4.js
- app/assets/javascripts/underscore.js
- app/assets/javascripts/backbone.js
- app/assets/javascripts/jquery.jqGrid.min.js
- app/assets/javascripts/views/avia_view_template.jst.hamljs
- app/assets/javascripts/views/avia_view.js.coffee

Perhaps I'm just taking the wrong approach here ... should I be using Jasmine to stub & mock out the calls to JST and jQuery? A strictly unit-testing approach says I should, in which case the lack of template access is a non-issue.

FYI I've put a bounty on this question over at http://stackoverflow.com/posts/8364013/ so if you want some karma feel free to chip in there :-)