public
Created

test-driving backbone views with jquery templates

  • Download Gist
1-problem.js
JavaScript
1 2 3 4 5 6 7 8
NutShell = Backbone.View.extend({
initialize: function(){
 
// road block!
this.template = $("#some-template-id");
 
}
});
2-template.erb
HTML+ERB
1 2 3 4 5 6
<script id="some-template-id" type="text/x-jquery-tmpl">
<h1>some template {{name}}</h1>
<div id="foo">
and stuff here. {{description}}
</div>
</script>
3-test-with-fixture.js
JavaScript
1 2 3 4 5 6 7 8 9
describe("a test with a fixture", function(){
beforeEach(function(){
 
// load my template for use in this spec!
loadFixtures("some-template-id.erb");
 
});
it("...", function(){ /* ... */ });
});
5-index.erb
HTML+ERB
1 2 3 4 5 6 7 8 9 10 11
<html>
<head>
 
<%= erb :'some-template-id' %>
 
...
</head>
<body>
...
</body>
</html>
6-load-path.js
JavaScript
1
jasmine.getFixtures().fixturesPath = '/views/';

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.