diff options
Diffstat (limited to 'test/promises.tests.js')
| -rw-r--r-- | test/promises.tests.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/promises.tests.js b/test/promises.tests.js new file mode 100644 index 0000000..3dd24be --- /dev/null +++ b/test/promises.tests.js @@ -0,0 +1,48 @@ +var assert = require("assert"); + +var promises = require("../lib/promises"); +var test = require("./test")(module); + +test("try", { + "when function succeeds with non-promise then promise is resolved": function() { + return promises.try(function() { + return "success"; + }).then(function(result) { + assert.strictEqual(result, "success"); + }); + }, + + "when function succeeds with promise then promise is resolved": function() { + return promises.try(function() { + return promises.resolve("success"); + }).then(function(result) { + assert.strictEqual(result, "success"); + }); + }, + + "when function throws error then promise is rejected": function() { + return promises.try(function() { + throw new Error("failure"); + }).then( + function() { + assert.fail("Expected rejection"); + }, + function(error) { + assert.strictEqual(error.message, "failure"); + } + ); + }, + + "when function fails with promise then promise is rejected": function() { + return promises.try(function() { + return promises.reject(new Error("failure")); + }).then( + function() { + assert.fail("Expected rejection"); + }, + function(error) { + assert.strictEqual(error.message, "failure"); + } + ); + } +}); |
