Skip to content

Commit 84fa128

Browse files
committed
add test cases for object index lookup - the second one annoyingly fails :(
1 parent 9c990a1 commit 84fa128

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]]
@@ -361,6 +362,27 @@ describe('View insertion', function() {
361362
expect(view.get(context)).equal('<div><p><b>Hi</b></p></div>');
362363
});
363364

365+
it('attributes can be used as object index if defined as alias', 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>{{with @attr as #attr}}{{_page.objectA[#attr]}}{{/}}</p>');
371+
var view = views.find('body');
372+
expect(view.get(context)).equal('<div><p>first</p></div>');
373+
});
374+
375+
// This test fails
376+
it.skip('attributes can be used as object index', function() {
377+
var views = new templates.Views();
378+
context.meta.views = views;
379+
views.register('body', '<view is="section" attr="{{_page.letters[0]}}"><b>Hi</b></view>');
380+
views.register('section', '<div><view is="paragraph" attr="{{@attr}}"></view></div>');
381+
views.register('paragraph', '<p>{{_page.objectA[@attr]}}</p>');
382+
var view = views.find('body');
383+
expect(view.get(context)).equal('<div><p>first</p></div>');
384+
});
385+
364386
it('views can define custom child attribute tags', function() {
365387
var views = new templates.Views();
366388
context.meta.views = views;

0 commit comments

Comments
 (0)