Skip to content

Commit 8993eb2

Browse files
committed
add test cases for object index lookup - the second one annoyingly fails :(
1 parent 821374e commit 8993eb2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/templates.mocha.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var model = {
1212
, yep: true
1313
, nope: false
1414
, nada: null
15+
, objectA: { 'A': 'first', 'B': 'second' }
1516
, letters: ['A', 'B', 'C']
1617
, emptyList: []
1718
, matrix: [[0, 1], [1, 0]]
@@ -350,6 +351,27 @@ describe('View insertion', function() {
350351
expect(view.get(context)).equal('<div><p><b>Hi</b></p></div>');
351352
});
352353

354+
it('attributes can be used as object index if defined as alias', function() {
355+
var views = new templates.Views();
356+
context.meta.views = views;
357+
views.register('body', '<view is="section" attr="{{_page.letters[0]}}"><b>Hi</b></view>');
358+
views.register('section', '<div><view is="paragraph" attr="{{@attr}}"></view></div>');
359+
views.register('paragraph', '<p>{{with @attr as #attr}}{{_page.objectA[#attr]}}{{/}}</p>');
360+
var view = views.find('body');
361+
expect(view.get(context)).equal('<div><p>first</p></div>');
362+
});
363+
364+
// This test fails
365+
it.skip('attributes can be used as object index', function() {
366+
var views = new templates.Views();
367+
context.meta.views = views;
368+
views.register('body', '<view is="section" attr="{{_page.letters[0]}}"><b>Hi</b></view>');
369+
views.register('section', '<div><view is="paragraph" attr="{{@attr}}"></view></div>');
370+
views.register('paragraph', '<p>{{_page.objectA[@attr]}}</p>');
371+
var view = views.find('body');
372+
expect(view.get(context)).equal('<div><p>first</p></div>');
373+
});
374+
353375
it('views can define custom child attribute tags', function() {
354376
var views = new templates.Views();
355377
context.meta.views = views;

0 commit comments

Comments
 (0)