Skip to content

Instantly share code, notes, and snippets.

@alfasin
Created December 16, 2017 09:25
Show Gist options
  • Save alfasin/14de298c9fae0464df12d1553bf888a5 to your computer and use it in GitHub Desktop.
Save alfasin/14de298c9fae0464df12d1553bf888a5 to your computer and use it in GitHub Desktop.
An example of how to use `tap` to create unit-tests
var sum = function (a, b, f) { return f(null, a + b) }
var test = require('tap').test;
test('sums 1 and 2', function (t) {
sum(1, 2, function (err, result) {
t.notOk(err, 'no error');
t.equal(result, 3, '1 + 2 should be equal to 3');
t.end();
});
});
test('sums 5 and 0', function (t) {
sum(5, 0, function(err, result) {
t.notOk(err, 'no error');
t.equal(result, 5, '5 + 0 should be equal to 3');
t.end();
});
});
test('sums 5 and -2', function (t) {
sum(5, -2, function (err, result) {
t.notOk(err, 'no error');
t.equal(result, 3, '5 + -2 should be equal to 3');
t.end();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment