Created
March 21, 2012 18:34
-
-
Save jairodemorais/2150895 to your computer and use it in GitHub Desktop.
Jasmin test running on browser and nodejs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Spec file filename: renderTestSpec.js*/ | |
describe ("Test the basic functionality of dust", function() { | |
//Execute each test | |
for (var index = 0; index < dustExamples.length; index++) { | |
var test = dustExamples[index]; | |
it (test.message, render(test)); | |
}; | |
}); | |
function render(test) { | |
// this should return a function to keep the variable scope inside the loop. | |
return function() { | |
try { | |
dust.loadSource(dust.compile(test.source, test.name)); | |
dust.render(test.name, test.context, function(err, output) { | |
expect(err).toBeNull(); | |
expect(test.expected).toEqual(output); | |
}); | |
} | |
catch (error) { | |
expect(test.error || {} ).toEqual(error.message); | |
} | |
}; | |
} | |
/* Tests filename: examples.js */ | |
var dustExamples = [ | |
{ | |
name: "error", | |
source: "RRR {##}", | |
context: { name: "Mick", count: 30 }, | |
error: 'Expected buffer, comment, partial, reference, section or special but "{" found. At line : 1, column : 5', | |
message: "should test that the error message shows line and column." | |
}, | |
{ | |
name: "intro", | |
source: "{#stream}{#delay}{.}{/delay}{/stream}", | |
context: (function(){ | |
var d = 1; | |
return { | |
stream: function() { | |
return "asynchronous templates for the browser and node.js".split(''); | |
}, | |
delay: function(chunk, context, bodies) { | |
return chunk.map(function(chunk) { | |
setTimeout(function() { | |
chunk.render(bodies.block, context).end(); | |
}, d++ * 15); | |
}); | |
} | |
} | |
}), | |
expected: '', | |
message: "should test the stream tag" | |
} | |
]; | |
// Check If we are executing client or nodejs version | |
if (typeof module !== "undefined" && typeof require !== "undefined") { | |
module.exports = dustExamples; // We're on node.js | |
} else { | |
window.dustExamples = dustExamples; // We're on the browser | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment