summaryrefslogtreecommitdiffstats
path: root/spec/utils.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2013-06-01 23:45:43 -0500
committerkpdecker <kpdecker@gmail.com>2013-06-01 23:45:43 -0500
commitadda0569e0ec3fc363af9efbb23f5304c6d80fe2 (patch)
tree9952d7aed77f8710a53731bb98340d5468c9e931 /spec/utils.js
parentd13ae310d36a27fcbc333570f9b7ae9c7e641392 (diff)
downloadhandlebars.js-adda0569e0ec3fc363af9efbb23f5304c6d80fe2.zip
handlebars.js-adda0569e0ec3fc363af9efbb23f5304c6d80fe2.tar.gz
handlebars.js-adda0569e0ec3fc363af9efbb23f5304c6d80fe2.tar.bz2
Refactor qunit unit tests
Allows for testing node, browser, and precompiled modes in the node tests. Also reorganizes the qunit spec file to provide better organization.
Diffstat (limited to 'spec/utils.js')
-rw-r--r--spec/utils.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/utils.js b/spec/utils.js
new file mode 100644
index 0000000..135beb4
--- /dev/null
+++ b/spec/utils.js
@@ -0,0 +1,56 @@
+/*global shouldCompileTo */
+describe('utils', function() {
+ describe('#SafeString', function() {
+ it("constructing a safestring from a string and checking its type", function() {
+ var safe = new Handlebars.SafeString("testing 1, 2, 3");
+ safe.should.be.instanceof(Handlebars.SafeString);
+ (safe == "testing 1, 2, 3").should.equal(true, "SafeString is equivalent to its underlying string");
+ });
+
+ it("it should not escape SafeString properties", function() {
+ var name = new Handlebars.SafeString("<em>Sean O&#x27;Malley</em>");
+
+ shouldCompileTo('{{name}}', [{ name: name }], "<em>Sean O&#x27;Malley</em>");
+ });
+ });
+
+ describe('#escapeExpression', function() {
+ it('shouhld escape html', function() {
+ Handlebars.Utils.escapeExpression('foo<&"\'>').should.equal('foo&lt;&amp;&quot;&#x27;&gt;');
+ });
+ it('should not escape SafeString', function() {
+ var string = new Handlebars.SafeString('foo<&"\'>');
+ Handlebars.Utils.escapeExpression(string).should.equal('foo<&"\'>');
+
+ });
+ it('should handle falsy', function() {
+ Handlebars.Utils.escapeExpression('').should.equal('');
+ Handlebars.Utils.escapeExpression(undefined).should.equal('');
+ Handlebars.Utils.escapeExpression(null).should.equal('');
+ Handlebars.Utils.escapeExpression(false).should.equal('');
+
+ Handlebars.Utils.escapeExpression(0).should.equal('0');
+ });
+ it('should handle empty objects', function() {
+ Handlebars.Utils.escapeExpression({}).should.equal({}.toString());
+ Handlebars.Utils.escapeExpression([]).should.equal([].toString());
+ });
+ });
+
+ describe('#isEmpty', function() {
+ it('should not be empty', function() {
+ Handlebars.Utils.isEmpty(undefined).should.equal(true);
+ Handlebars.Utils.isEmpty(null).should.equal(true);
+ Handlebars.Utils.isEmpty(false).should.equal(true);
+ Handlebars.Utils.isEmpty('').should.equal(true);
+ Handlebars.Utils.isEmpty([]).should.equal(true);
+ });
+
+ it('should be empty', function() {
+ Handlebars.Utils.isEmpty(0).should.equal(false);
+ Handlebars.Utils.isEmpty([1]).should.equal(false);
+ Handlebars.Utils.isEmpty('foo').should.equal(false);
+ Handlebars.Utils.isEmpty({bar: 1}).should.equal(false);
+ });
+ });
+});