Note that there are some explanatory texts on larger screens.

plurals
  1. POBest Approach to Test Backbone Views with Templates Using Jasmine
    primarykey
    data
    text
    <p>I am learning backbone so I am building a simple Backbone app. I am using jasmine framework to test my backbone app.</p> <p>As luck would have it, my first jasmine test was for a Backbone View. This is a very simple view that uses a haml-js template. App users rails 3.1 so the whole thing is packaged via sprockets with the help of haml-sprockets gem, and it works.</p> <p>However when I test with jasmine I get an error</p> <blockquote> <p>TypeError: Cannot call method 'backbone/templates/admin_personal_attribute_template' of undefined</p> </blockquote> <p>I understand this is because haml-js template is not present.</p> <p>Normally this template is accessed like this:</p> <pre><code>$(this.el).html(window.JST["backbone/templates/admin_personal_attribute_template"]({pars:this.model.attributes})); </code></pre> <p>(i.e. haml-sprockets gem compiles is using haml-js and appends to window.JST).</p> <p>I am looking for the 'best', i.e. least disruptive and, hopefully, simple, way to test my views + templates in jasmine.</p> <p>I have found a number of ways to do it, but not sure as what is the 'best':</p> <ol> <li>Use jasmine-headless-webkit . This will utulize sprockets, but loose ability to access jasmine server, so simple but some loss of flexibility</li> <li>Using phantom.js as desribed by japhr (sorry stackoverflow prevented me from posting more links) will work around the server-side limitations, but this seems to be a very new and untested method, so flexible but not simple</li> <li>Pre-generate your templates as desribed <a href="http://pivotallabs.com/users/jb/blog/articles/1152-javascripttests-bind-reality-" rel="noreferrer">here</a>. This is conceptually simple, but require some maintenance - so some coding work</li> </ol> <p>Assuming I have a project with ~ 20 models and ~ 40 views and templates, what is the best way to go?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload