diff --git a/lib/bemxjst/index.js b/lib/bemxjst/index.js index 199eb145..a1593252 100644 --- a/lib/bemxjst/index.js +++ b/lib/bemxjst/index.js @@ -369,7 +369,7 @@ BEMXJST.prototype.renderContent = function renderContent(content, isBEM) { context._notNewList = false; if (isBEM) { - context.position = 1; + context.position = 0; context._listLength = 1; } diff --git a/test/bemcontext-position-test.js b/test/bemcontext-position-test.js index 7fb6b4de..53a1959f 100644 --- a/test/bemcontext-position-test.js +++ b/test/bemcontext-position-test.js @@ -4,75 +4,89 @@ var test = fixtures.test; describe('BEMContext this.position', function() { it('should have proper this.position', function() { test(function() { - block('b1').content()(function() { return this.position; }); + block('b').content()(function() { return this.position; }); }, [ - { block: 'b1' }, - { block: 'b1' }, - '', - { block: 'b1' }, - { - tag: 'div', - content: 'blah' - }, - { block: 'b1' } - ], '
1
' + - '
2
' + - '
3
' + - '
blah
' + - '
4
'); + { block: 'b' }, + { block: 'b' }, + { block: 'b' } + ], '
1
' + + '
2
' + + '
3
'); }); - it('should calc position', function() { + it('should not count not bem entities', function() { test(function() { - block('button').elem('inner').def()(function() { + block('b').content()(function() { return this.position; }); + }, [ + { block: 'b' }, + 42, + { block: 'b' }, + 'string', + { block: 'b' }, + null, + { block: 'b' }, + {}, + { block: 'b' } + ], '
1
' + + '42' + + '
2
' + + 'string' + + '
3
' + + '
4
' + + '
' + + '
5
'); + }); + + it('should calc position for nested elements', function() { + test(function() { + block('menu').elem('item').def()(function() { this.elemMods.pos = this.position; return applyNext(); }); }, { - block: 'button', - content: [ { elem: 'inner' }, { elem: 'inner' }, { elem: 'inner' } ] + block: 'menu', + content: [ { elem: 'item' }, { elem: 'item' }, { elem: 'item' } ] }, - '
' + - '
' + - '
' + - '
' + + ''); }); it('should calc position with array mess', function() { test(function() { - block('button').elem('inner').def()(function() { + block('menu').elem('item').def()(function() { this.elemMods.pos = this.position; return applyNext(); }); }, { - block: 'button', + block: 'menu', content: [ - [ { elem: 'inner' } ], - [ { elem: 'inner' }, [ { elem: 'inner' } ] ] + [ { elem: 'item' } ], + [ { elem: 'item' }, [ { elem: 'item' } ] ] ] }, - '
' + - '
' + - '
' + - '
' + + ''); }); it('should calc position for single block', function() { test(function() { - block('b').content()(function() { + block('single').content()(function() { return this.position; }); }, - [ { block: 'b' } ], - '
1
'); + { block: 'single' }, + '
1
'); }); - // TODO: FIX ME https://github.com/bem/bem-xjst/issues/174 - xit('should calc position for single block', function() { + it('should calc position for single nested block', function() { test(function() { block('b').content()(function() { return this.position; @@ -82,8 +96,7 @@ describe('BEMContext this.position', function() { '
1
'); }); - // TODO: FIX ME https://github.com/bem/bem-xjst/issues/174 - xit('should calc position for single element', function() { + it('should calc position for single element', function() { test(function() { block('b').elem('e').content()(function() { return this.position; @@ -92,4 +105,14 @@ describe('BEMContext this.position', function() { { block: 'b', content: { elem: 'e' } }, '
1
'); }); + + it('should calc position for nested blocks', function() { + test(function() { + block('*').cls()(function() { + return this.position; + }); + }, + { block: 'a1', content: { block: 'a2', content: { block: 'a3' } } }, + '
'); + }); });