From 54a950e10f8b06b1b5c99da4294cec1360bc72d1 Mon Sep 17 00:00:00 2001 From: Sahab Yazdani Date: Tue, 26 Apr 2011 17:46:35 -0400 Subject: [PATCH] Use QUnit raises function instead of manual try/catch blocks --- test/unit.js | 65 +++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/test/unit.js b/test/unit.js index 4b1194d..2fe3e0b 100644 --- a/test/unit.js +++ b/test/unit.js @@ -43,18 +43,19 @@ test("Parser", function() { 'Hello\n\n\nWorld\n', 'Preservation of white space' ); - - try { - Mustache.to_html( - '{{=tag1}}', - { tag1: 'Hello' }, - {} - ); - ok(false); - } catch (e) { - equals(e.message, 'Unexpected end of document.'); - } + raises( + function() { + Mustache.to_html( + '{{=tag1}}', + { tag1: 'Hello' }, + {} + ); + }, function(e) { + return e.message === 'Unexpected end of document.'; + }, + 'Malformed tags should be handled correctly.' + ); var partials = { 'partial' : '{{key}}' }; Mustache.compile('{{>partial}}', partials ); @@ -368,16 +369,18 @@ test("'>' (Partials)", function() { '1\n\n1.1\n\n1.1.1\n\n\n' ); - try { - Mustache.to_html( - '{{>partial}}', - {}, - {partal: ''} - ); - ok(false); - } catch(e) { - equals(e.message, "Unknown partial 'partial'"); - } + raises( + function() { + Mustache.to_html( + '{{>partial}}', + {}, + {partal: ''} + ); + }, function(e) { + return e.message === "Unknown partial 'partial'"; + }, + 'Missing partials should be handled correctly.' + ); }); test("'=' (Set Delimiter)", function() { @@ -442,20 +445,20 @@ test("'%' (Pragmas)", function() { ); // matches unknown_pragma.txt - try { - equals( + + raises( + function() { Mustache.to_html( '{{%I-HAVE-THE-GREATEST-MUSTACHE}}\n', {}, {} - ), - 'hello world ', - 'IMPLICIT-ITERATOR pragma' - ); - ok(false); - } catch (e) { - equals(e.message, 'This implementation of mustache doesn\'t understand the \'I-HAVE-THE-GREATEST-MUSTACHE\' pragma'); - } + ); + }, + function(e) { + return e.message === 'This implementation of mustache doesn\'t understand the \'I-HAVE-THE-GREATEST-MUSTACHE\' pragma'; + }, + 'Notification of unimplemented pragmas' + ); equals( Mustache.to_html(