Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6889967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:13:22+00:00 2026-05-27T06:13:22+00:00

I’m trying to test some backbone.js views using Jasmine (via jasmine-headless-webkit). Everything is working

  • 0

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.

Any tips – either on my approach to testing, or the specific JST failure, would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:13:22+00:00Added an answer on May 27, 2026 at 6:13 am

    No need to stub, you just need to set up your asset paths correctly. In order to take advantage of the Sprockets integration in 0.8.0 and above, the best way to set up your jasmine.yml file would be like this:

    src_dir: app/assets/javascripts
    asset_paths:
    - lib/assets/javascripts
    src_files:
    - "**/*"
    

    This will set up Sprockets to look in app/assets/javascripts and lib/assets/javascripts, and will tell jasmine-headless-webkit to pull every possible file in both directories. Jasmine’s normal file requiring wouldn’t be used in this case, just Sprockets.

    Then, set up your require statements like you would normally in your JS files. So in ‘application.js.coffee’:

    #= require jquery-1.6.4
    #= require avia
    #= require underscore
    #= require backbone
    #= require jquery.jqGrid.min
    #= require_tree .
    
    alert "Look, Internet codes!"
    

    And in avia_view.js.coffee:

    #= require views/avia_view_template.jst.hamljs
    
    class window.AviaView extends Backbone.View
      template: JST['views/avia_view_template']
      ... code ...
    

    Of course, those .hamljs templates won’t get loaded unless a Sprockets-capable Haml processor has been loaded. So you would want to have a Gemfile that had at least this in it:

    gem 'jasmine-headless-webkit'
    gem 'haml-sprockets'
    # also bring in backbone and jquery
    gem 'jquery-rails'
    gem 'backbone-rails'
    

    Then, if your application itself knows what to do when those vendored JS gems are loaded, you could get rid of you own copies of jQuery and Backbone, and you’d also have .hamljs templates available. At that point, you should run using Bundler:

    bundle exec jasmine-headless-webkit
    

    Last thing, the best way to make sure everything’s actually getting loaded is to use the list option:

    bundle exec jasmine-headless-webkit -l
    

    That will run everything through JHW’s and Sprockets’ file loaders and print out the order of files to be included. This will help diagnose require problems, since you always have to deal with both Jasmine-style and Sprockets-style loading in a single scenario. Setting up your src files to be loaded entirely via Sprockets simplifies the process a lot, so I would recommend a setup a lot like this one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.