Here's an example specification written with Willful:
require("willful"); var assert = require("assert"); // start a new specification: the("function I'm spec'ing", function (will) { // start a new behavior: will("exhibit the behavior I expect", function(done) { // test something via Node's built-in assert module assert.ok(true) // signal that the behavior's verification is done done(); }); // start a second behavior (this one'll fail) will("not exhibit the behavior I expect", function(done) { assert.equal(true, false); done(); }); });
I looked at many different unit testing and spec'ing libraries when I started to TDD my Node app, and none of them made me quite happy enough. minitest.js came closest, and the design for Willful was influenced by it.
(Bonus: If you look at Willful's own specs, you'll see my approach to stubbing dependencies in Node (such as stubbing sys.puts for reporting). I'll write another 'blog post relating how I came to that approach soon.)
No comments:
Post a Comment