-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More tests for coverage #405
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,10 +81,7 @@ BEMHTML.prototype.render = function render(context, | |
|
||
var isBEM = bem; | ||
if (isBEM === undefined) { | ||
if (ctx.bem === undefined) | ||
isBEM = entity.block || entity.elem; | ||
else | ||
isBEM = ctx.bem; | ||
isBEM = entity.block || entity.elem; | ||
} | ||
isBEM = !!isBEM; | ||
|
||
|
@@ -93,7 +90,7 @@ BEMHTML.prototype.render = function render(context, | |
|
||
var addJSInitClass = jsParams && ( | ||
this._elemJsInstances ? | ||
(entity.block || entity.elem) : | ||
entity.block : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure it's useless case but it works now: BEMHTML.apply({ elem: 'e1' }); // '<div class="__e1"></div>' |
||
(entity.block && !entity.elem) | ||
); | ||
|
||
|
@@ -284,9 +281,6 @@ BEMHTML.prototype.renderMix = function renderMix(entity, | |
context.elem = oldElem; | ||
context.block = oldBlock; | ||
|
||
if (!nestedMix) | ||
continue; | ||
|
||
for (var j = 0; j < nestedMix.length; j++) { | ||
var nestedItem = nestedMix[j]; | ||
if (!nestedItem) continue; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ var ClassBuilder = require('./class-builder').ClassBuilder; | |
var utils = require('./utils'); | ||
|
||
function BEMXJST(options) { | ||
this.options = options || {}; | ||
this.options = options; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of |
||
|
||
this.entities = null; | ||
this.defaultEnt = null; | ||
|
@@ -117,10 +117,6 @@ BEMXJST.prototype.compile = function compile(code) { | |
|
||
BEMXJST.prototype.recompileInput = function recompileInput(code) { | ||
var args = BEMXJST.prototype.locals; | ||
// Reuse function if it already has right arguments | ||
if (typeof code === 'function' && code.length === args.length) | ||
return code; | ||
|
||
var out = code.toString(); | ||
|
||
// Strip the function | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,5 +146,60 @@ describe('API compile', function() { | |
template.apply({ block: 'b1' }); | ||
}); | ||
}); | ||
|
||
it('should throw bem-xjst error on template with no block', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without block |
||
assert.throws(function() { | ||
bemxjst.compile(function() { | ||
attrs()(function() { return { a: 1 }; }); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Runtime lint mode', function() { | ||
function captureStream(stream) { | ||
var oldWrite = stream.write; | ||
var buf = ''; | ||
|
||
stream.write = function(chunk) { | ||
buf += chunk.toString(); | ||
oldWrite.apply(stream, arguments); | ||
}; | ||
|
||
return { | ||
unhook: function unhook() { stream.write = oldWrite; }, | ||
captured: function() { return buf; } | ||
}; | ||
} | ||
|
||
var hook; | ||
beforeEach(function() { hook = captureStream(process.stderr); }); | ||
afterEach(function() { hook.unhook(); }); | ||
|
||
it('should work with runtimeLint option', function() { | ||
var template = bemxjst.compile(function() { | ||
block('b__e').content()('test'); | ||
}, { runtimeLint: true }); | ||
|
||
template.apply({ block: 'b__e' }); | ||
|
||
var stderr = hook.captured(); | ||
assert.equal( | ||
stderr.substr(0, 17), | ||
'\nBEM-XJST WARNING' | ||
); | ||
}); | ||
}); | ||
|
||
describe('context option', function() { | ||
it('should work with context option', function() { | ||
assert.doesNotThrow(function() { | ||
var template = bemxjst.compile(function() { | ||
block('b').content()('test'); | ||
}, { context: 'this' }); | ||
|
||
template.apply({ block: 'b' }); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of
bem
in line 82 is result ofbem()
mode execution. Andbem()
returnsthis.ctx.bem
by default.