Commit 73cd1284 authored by Oskar Kalbag's avatar Oskar Kalbag

Improved the error message for unknown operators in conditionals.

parent 8e4012e4
......@@ -170,7 +170,7 @@ tally = (root, obj) ->
when "doesNotContain" # In Distal this is nc (does not contain)
attr = (obj2 and obj2.indexOf(attr[2]) < 0)
else
throw new Error(node)
throw new Error('Unknown conditional operator (‘' + attr[1] + '’) in ' + node.outerHTML + '. Valid operators are: not:, is, isNot, isGreatherThan, isLessThan, contains, and doesNotContain.');
else
attr = obj2
if attr
......
......@@ -160,7 +160,7 @@ Forked from Distal by mocking@gmail.com (https://code.google.com/p/distal/)
attr = obj2 && obj2.indexOf(attr[2]) < 0;
break;
default:
throw new Error(node);
throw new Error('Unknown conditional operator (‘' + attr[1] + '’) in ' + node.outerHTML + '. Valid operators are: not:, is, isNot, isGreatherThan, isLessThan, contains, and doesNotContain.');
}
} else {
attr = obj2;
......
......@@ -52,9 +52,9 @@ describe 'Tally', ->
# Note: should.js requires you to run the code that could throw an exception in an anonymous function and
# ===== apply .should.throw() to that. My instinct was to actually run the function itself and apply it to that.
it 'should fail conditionals with unknown operators', ->
it 'should throw an error when it encounters an unknown operator in a conditional', ->
(->
tally('<html><p data-tally-if="operand isLessThanny 2"></p></html>', {operand: 1})).should.throw('[ P ]')
tally('<html><p data-tally-if="operand isLessThanny 2"></p></html>', {operand: 1})).should.throw('Unknown conditional operator (‘isLessThanny’) in <p data-tally-if="operand isLessThanny 2"></p>. Valid operators are: not:, is, isNot, isGreatherThan, isLessThan, contains, and doesNotContain.')
#
# Error checking tests for data-tally-attribute.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment