Skip to content

Commit 18a2497

Browse files
committed
add test cases for object index lookup - the second one annoyingly fails :(
1 parent 08c0942 commit 18a2497

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]]
@@ -455,6 +456,27 @@ describe('View insertion', function() {
455456
views.register('paragraph', '<p>{{@content}}</p>');
456457
var view = views.find('body');
457458
expect(view.get(context)).equal('<div><p><b>Hi</b></p></div>');
459+
});
460+
461+
it('attributes can be used as object index if defined as alias', function() {
462+
var views = new templates.Views();
463+
context.meta.views = views;
464+
views.register('body', '<view is="section" attr="{{_page.letters[0]}}"><b>Hi</b></view>');
465+
views.register('section', '<div><view is="paragraph" attr="{{@attr}}"></view></div>');
466+
views.register('paragraph', '<p>{{with @attr as #attr}}{{_page.objectA[#attr]}}{{/}}</p>');
467+
var view = views.find('body');
468+
expect(view.get(context)).equal('<div><p>first</p></div>');
469+
});
470+
471+
// This test fails
472+
it.skip('attributes can be used as object index', function() {
473+
var views = new templates.Views();
474+
context.meta.views = views;
475+
views.register('body', '<view is="section" attr="{{_page.letters[0]}}"><b>Hi</b></view>');
476+
views.register('section', '<div><view is="paragraph" attr="{{@attr}}"></view></div>');
477+
views.register('paragraph', '<p>{{_page.objectA[@attr]}}</p>');
478+
var view = views.find('body');
479+
expect(view.get(context)).equal('<div><p>first</p></div>');
458480
});
459481
});
460482

0 commit comments

Comments
 (0)