diff --git a/lib/bemhtml/index.js b/lib/bemhtml/index.js index a6b0f72d..2c86594b 100644 --- a/lib/bemhtml/index.js +++ b/lib/bemhtml/index.js @@ -273,6 +273,10 @@ BEMHTML.prototype.renderMix = function(entity, mix, jsParams, addJSInitClass) { if (!nestedMix) continue; + // Transform nestedMix to the single-item array if it's not array + if (!Array.isArray(nestedMix)) + nestedMix = [ nestedMix ]; + for (var j = 0; j < nestedMix.length; j++) { var nestedItem = nestedMix[j]; if (!nestedItem) continue; diff --git a/test/bemjson-mix-test.js b/test/bemjson-mix-test.js index f69b7b2d..e9cc1891 100644 --- a/test/bemjson-mix-test.js +++ b/test/bemjson-mix-test.js @@ -2,7 +2,16 @@ var fixtures = require('./fixtures')('bemhtml'); var test = fixtures.test; describe('BEMJSON mix', function() { - it('should support mix in json', function() { + it('should support string mix in json', function() { + test(function() {}, + { + block: 'b1', + mix: 'b2' + }, + '
'); + }); + + it('should support object mix in json', function() { test(function() {}, { block: 'b1', @@ -11,6 +20,28 @@ describe('BEMJSON mix', function() { ''); }); + it('should support array with string mix in json', function() { + test(function() {}, + { + block: 'b1', + mix: [ + 'b2' + ] + }, + ''); + }); + + it('should support array with object mix in json', function() { + test(function() {}, + { + block: 'b1', + mix: [ + { block: 'b2' } + ] + }, + ''); + }); + it('should not propagate parent elem to JS params', function() { test(function() {}, { @@ -240,7 +271,7 @@ describe('BEMJSON mix', function() { }); describe('nested mixes', function() { - it('should support nested mix', function() { + it('should support nested mix in json', function() { test(function() {}, { block: 'b1', @@ -260,6 +291,110 @@ describe('BEMJSON mix', function() { ''); }); + it('should support string mix ' + + 'with nested string mix in bemhtml', function() { + test(function() { + block('b2')( + addMods()('b3') + ); + }, { + block: 'b1', + mix: 'b2' + }, ''); + }); + + it('should support string mix ' + + 'with nested object mix in bemhtml', function() { + test(function() { + block('b2')( + addMods()({ block: 'b3' }) + ); + }, { + block: 'b1', + mix: 'b2' + }, ''); + }); + + it('should support string mix ' + + 'with nested array of strings mix in bemhtml', function() { + test(function() { + block('b2')( + addMods()([ 'b3' ]) + ); + }, { + block: 'b1', + mix: 'b2' + }, ''); + }); + + it('should support string mix ' + + 'with nested array of objects mix in bemhtml', function() { + test(function() { + block('b2')( + addMods()([ { block: 'b3' } ]) + ); + }, { + block: 'b1', + mix: 'b2' + }, ''); + }); + + it('should support object mix ' + + 'with nested string mix in bemhtml', function() { + test(function() { + block('b2')( + addMods()('b3') + ); + }, { + block: 'b1', + mix: { + block: 'b2' + } + }, ''); + }); + + it('should support object mix ' + + 'with nested object mix in bemhtml', function() { + test(function() { + block('b2')( + addMods()({ block: 'b3' }) + ); + }, { + block: 'b1', + mix: { + block: 'b2' + } + }, ''); + }); + + it('should support object mix ' + + 'with nested array of strings mix in bemhtml', function() { + test(function() { + block('b2')( + addMods()([ 'b3' ]) + ); + }, { + block: 'b1', + mix: { + block: 'b2' + } + }, ''); + }); + + it('should support object mix ' + + 'with nested array of objects mix in bemhtml', function() { + test(function() { + block('b2')( + addMods()([ { block: 'b3' } ]) + ); + }, { + block: 'b1', + mix: { + block: 'b2' + } + }, ''); + }); + it('should support nested mix with js params', function() { test(function() {}, {