Skip to content

Commit

Permalink
added more tests for errors.jquery.js.
Browse files Browse the repository at this point in the history
  • Loading branch information
toolness committed May 1, 2012
1 parent 50c688c commit bcddab5
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions test/test-errors.jquery.js
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
module("jQuery.fn.fillError()"); module("errors.jquery.js");


test("raises nice exception when template is not found", function() { test("$.fn.fillError() raises nice err when template not found", function() {
try { try {
var div = $('<div></div>').fillError({type: "BLARGY"}); var div = $('<div></div>').fillError({type: "BLARGY"});
} catch (e) { } catch (e) {
Expand All @@ -10,7 +10,7 @@ test("raises nice exception when template is not found", function() {
ok(false, "Exception not thrown!"); ok(false, "Exception not thrown!");
}); });


test("works when template is found", function() { test("$.fn.fillError() works when template is found", function() {
var templates = $('<div class="error-msg BLARGY">' + var templates = $('<div class="error-msg BLARGY">' +
'<p>{{foo.bar}}</p></div>'); '<p>{{foo.bar}}</p></div>');
var div = $('<div></div>').fillError({ var div = $('<div></div>').fillError({
Expand All @@ -19,3 +19,38 @@ test("works when template is found", function() {
}, templates); }, templates);
equal(div.html(), "<p>hi</p>"); equal(div.html(), "<p>hi</p>");
}); });

test("$.fn.errorHighlightInterval() works", function() {
deepEqual($('<div data-highlight="1"></div>').errorHighlightInterval(),
{start: 1, end: undefined}, "works w/ start only");
deepEqual($('<div data-highlight="1,2"></div>').errorHighlightInterval(),
{start: 1, end: 2}, "works w/ number pair");
});

test("$.fn.eachErrorHighlight() works", function() {
var args = [];
var div = $('<div><div data-highlight="1,2"></div>' +
'<em data-highlight="3"></em></div>');
div.eachErrorHighlight(function(start, end, i) {
args.push({
node: this.nodeName,
start: start,
end: end,
i: i
});
});
deepEqual(args, [
{
"end": 2,
"i": 0,
"node": "DIV",
"start": 1
},
{
"end": undefined,
"i": 1,
"node": "EM",
"start": 3
}
]);
});

0 comments on commit bcddab5

Please sign in to comment.