Commit 198b35e2 authored by Oskar Kalbag's avatar Oskar Kalbag

Improved the error messages for the missing attribute errors to include the...

Improved the error messages for the missing attribute errors to include the missing attribute name/value
parent 3621ec39
......@@ -361,8 +361,6 @@ tally = (root, obj) ->
# Ignore empty spaces
attr = attr.trim()
# console.log('Attr: >' + attr + '<')
if attr == ''
throw new Error('empty data-tally-attribute definition on element: ' + node.outerHTML)
......@@ -379,7 +377,7 @@ tally = (root, obj) ->
throw new Error('missing attribute name for attribute ' + i)
if not attr[1]
throw new Error('missing attribute value for attribute ' + i)
throw new Error('missing attribute value for attribute ' + i + ' (\'' + name + '\')')
value = resolve(obj, attr[1])
value = "" if value is `undefined`
......
......@@ -316,7 +316,7 @@ Forked from Distal by mocking@gmail.com (https://code.google.com/p/distal/)
throw new Error('missing attribute name for attribute ' + i);
}
if (!attr[1]) {
throw new Error('missing attribute value for attribute ' + i);
throw new Error('missing attribute value for attribute ' + i + ' (\'' + name + '\')');
}
value = resolve(obj, attr[1]);
if (value === undefined) {
......
......@@ -59,6 +59,10 @@ describe 'Tally', ->
#
# Error checking tests for data-tally-attribute.
#
it 'should fail if an attribute has a missing value', ->
(->
tally('<html><p data-tally-attribute="href"></p></html>', {theURL: 'http://aralbalkan.com'})).should.throw('missing attribute value for attribute 0 (\'href\')')
it 'should not fail if a single attribute ends with a semi-colon', ->
(->
tally('<html><p data-tally-attribute="href theURL;"></p></html>', {theURL: 'http://aralbalkan.com'})).should.not.throw()
......@@ -69,11 +73,11 @@ describe 'Tally', ->
it 'should fail if an attribute just has a semi‐colon in it', ->
(->
tally('<html><p data-tally-attribute=";"></p></html>', {})).should.throw('missing attribute value for attribute 0')
tally('<html><p data-tally-attribute=";"></p></html>', {})).should.throw('missing attribute value for attribute 0 (\';\')')
it 'should fail if an attribute just multiple semi‐colons in it', ->
(->
tally('<html><p data-tally-attribute=";;"></p></html>', {})).should.throw('missing attribute value for attribute 0')
tally('<html><p data-tally-attribute=";;"></p></html>', {})).should.throw('missing attribute value for attribute 0 (\';;\')')
it 'should fail if an attribute just multiple semi‐colons with spaces between them in it', ->
(->
......
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