Skip to content

Instantly share code, notes, and snippets.

@chrisconley
Created June 27, 2011 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisconley/1049557 to your computer and use it in GitHub Desktop.
Save chrisconley/1049557 to your computer and use it in GitHub Desktop.
// Both tests fail with `view.$().text()` being empty.
test("should pass content as context when using {{#each}} helper within {{#with}} helper", function() {
var view = SC.View.create({
template: SC.Handlebars.compile('{{#with content}}{{#each releases}}Mac OS X {{version}}: {{name}} {{/each}}{{/with}}'),
content: {
releases: [ { version: '10.7',
name: 'Lion' },
{ version: '10.6',
name: 'Snow Leopard' },
{ version: '10.5',
name: 'Leopard' } ]
}
});
SC.run(function() { view.append(); });
equals(view.$().text(), "Mac OS X 10.7: Lion Mac OS X 10.6: Snow Leopard Mac OS X 10.5: Leopard ", "prints each item in sequence");
});
test("should pass content as context when using {{#each}} helper within {{#if}} helper", function() {
var view = SC.View.create({
template: SC.Handlebars.compile('{{#if content}}{{#each content.releases}}Mac OS X {{version}}: {{name}} {{/each}}{{/if}}'),
content: {
releases: [ { version: '10.7',
name: 'Lion' },
{ version: '10.6',
name: 'Snow Leopard' },
{ version: '10.5',
name: 'Leopard' } ]
}
});
SC.run(function() { view.append(); });
equals(view.$().text(), "Mac OS X 10.7: Lion Mac OS X 10.6: Snow Leopard Mac OS X 10.5: Leopard ", "prints each item in sequence");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment