[Pkg-javascript-commits] [node-jade] 45/72: Add tests for normalize and normalizeFn
Jelmer Vernooij
jelmer at moszumanska.debian.org
Sun Jul 3 18:03:28 UTC 2016
This is an automated email from the git hooks/post-receive script.
jelmer pushed a commit to annotated tag upstream/1.0.0
in repository node-jade.
commit e393fb41186839d8a841bd29453f5fd3b2b54d1a
Author: Timothy Gu <timothygu99 at gmail.com>
Date: Tue Jul 7 18:09:08 2015 -0700
Add tests for normalize and normalizeFn
When ES6 computed property names are supported this could be simplified.
---
test/index.js | 1 +
test/normalize.js | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+)
diff --git a/test/index.js b/test/index.js
index 7b67ec6..8ad0423 100644
--- a/test/index.js
+++ b/test/index.js
@@ -37,3 +37,4 @@ require('./render');
require('./render-async');
require('./input-formats');
require('./output-format');
+require('./normalize');
diff --git a/test/normalize.js b/test/normalize.js
new file mode 100644
index 0000000..5cba1c4
--- /dev/null
+++ b/test/normalize.js
@@ -0,0 +1,79 @@
+'use strict';
+
+var assert = require('assert');
+var test = require('./test');
+var tr = require('../');
+
+function testSync (funcName, bodyVar, specs) {
+ var func = tr[funcName];
+ var bodyType = specs.good[0],
+ body = specs.good[1],
+ notBodyType = specs.bad[0],
+ notBody = specs.bad[1];
+
+ test(funcName, function () {
+ test(bodyType + ' => { ' + bodyVar + ', dependencies }', function () {
+ var normalized = func(body);
+ var expected = { dependencies: [] };
+ expected[bodyVar] = body;
+ assert.deepEqual(normalized, expected);
+ });
+
+ test('{ ' + bodyVar + ': ' + bodyType + ' } => { ' + bodyVar + ', dependencies }', function () {
+ var input = {};
+ input[bodyVar] = body;
+ var normalized = func(input);
+ input.dependencies = [];
+ assert.deepEqual(normalized, input);
+ });
+
+ test('{ ' + bodyVar + ': ' + bodyType + ', dependencies: [] } => { ' + bodyVar + ', dependencies }', function () {
+ var input = { dependencies: [] };
+ input[bodyVar] = body;
+ var normalized = func(input);
+ assert.deepEqual(normalized, input);
+
+ input.dependencies = [ '/tmp/a.txt' ];
+ normalized = func(input);
+ assert.deepEqual(normalized, input);
+ });
+
+ test(notBodyType + ' => throw', function () {
+ assert.throws(function () {
+ func(notBody);
+ }, /Invalid result object/);
+ });
+
+ test('{ blah: ' + bodyType + ' } => throw', function () {
+ var input = { blah: body };
+ assert.throws(function () {
+ func(input);
+ }, /Invalid result object/);
+ });
+
+ test('{ ' + bodyVar + ': ' + notBodyType + ', dependencies: [] } => throw', function () {
+ var input = { dependencies: [] };
+ input[bodyVar] = notBody;
+ assert.throws(function () {
+ func(input);
+ }, /Invalid result object/);
+ });
+
+ test('{ ' + bodyVar + ': ' + bodyType + ', dependencies: Number } => throw', function () {
+ var input = { dependencies: 1 };
+ input[bodyVar] = body;
+ assert.throws(function () {
+ func(input);
+ }, /dependencies .* array/);
+ });
+ });
+}
+
+testSync('normalize', 'body', {
+ good: [ 'String', '<html></html>' ],
+ bad: [ 'Function', function () {} ]
+});
+testSync('normalizeFn', 'fn', {
+ good: [ 'Function', function () {} ],
+ bad: [ 'String', '<html></html>' ]
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-jade.git
More information about the Pkg-javascript-commits
mailing list