Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit f54db83

Browse files
committed
Add unit tests for pattern_engines.js and individual pattern engines
1 parent 37bacdc commit f54db83

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

test/pattern_engines_tests.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
(function () {
2+
'use strict';
3+
4+
var patternEngines = require('../builder/pattern_engines/pattern_engines');
5+
var of = require('../builder/object_factory');
6+
7+
// the mustache test pattern, stolen from object_factory unit tests
8+
var mustacheTestPattern = new of.oPattern('source/_patterns/00-atoms/00-global/00-colors-alt.mustache', '00-atoms/00-global', '00-colors-alt.mustache', {d: 123});
9+
var engineNames = Object.keys(patternEngines);
10+
11+
12+
exports['patternEngines support functions'] = {
13+
'getEngineNameForPattern returns "mustache" from test pattern': function (test) {
14+
var engineName = patternEngines.getEngineNameForPattern(mustacheTestPattern);
15+
test.equals(engineName, 'mustache');
16+
test.done();
17+
},
18+
'getEngineForPattern returns a reference to the mustache engine from test pattern': function (test) {
19+
var engine = patternEngines.getEngineForPattern(mustacheTestPattern);
20+
test.equals(engine, patternEngines.mustache);
21+
test.done();
22+
}
23+
};
24+
25+
// testProps() utility function: given an object, and a hash of expected
26+
// 'property name':'property type' pairs, verify that the object contains each
27+
// expected property, and that each property is of the expected type.
28+
function testProps(object, propTests, test) {
29+
30+
// function to test each expected property is present and the correct type
31+
function testProp(propName, typeString) {
32+
test.ok(object.hasOwnProperty(propName), '"' + propName + '" prop should be present');
33+
test.ok(typeof object[propName] === typeString, '"' + propName + '" prop should be of type ' + typeString);
34+
}
35+
36+
// go over each property test and run it
37+
Object.keys(propTests).forEach(function (propName) {
38+
var propType = propTests[propName];
39+
testProp(propName, propType);
40+
});
41+
}
42+
43+
exports['patternEngines initialization'] = {
44+
'patternEngines object contains at least the default mustache engine': function (test) {
45+
test.expect(1);
46+
test.ok(patternEngines.hasOwnProperty('mustache'));
47+
test.done();
48+
}
49+
};
50+
51+
// make one big test group for each pattern engine
52+
engineNames.forEach(function (engineName) {
53+
exports[engineName + ' patternEngine'] = {
54+
'engine contains expected properties and methods': function (test) {
55+
56+
var propertyTests = {
57+
'engine': 'object',
58+
'name': 'string',
59+
'fileExtension': 'string',
60+
'renderPattern': 'function',
61+
'findPartials': 'function'
62+
};
63+
64+
test.expect(Object.keys(propertyTests).length * 2);
65+
testProps(patternEngines[engineName], propertyTests, test);
66+
test.done();
67+
}
68+
};
69+
});
70+
71+
})();

0 commit comments

Comments
 (0)