Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Add tests for promise support (#329)

Domenic Denicolaa1662844cbf6
diff --git a/test/runnable.js b/test/runnable.js
index 29d8fd6b..ee766217 100644
--- a/test/runnable.js
+++ b/test/runnable.js
@@ -242,5 +242,72 @@ describe('Runnable(title, fn)', function(){
it('should allow a timeout of 0')
})
+ describe('when fn returns a promise', function(){
+ describe('when the promise is fulfilled with no value', function(){
+ var fulfilledPromise = {
+ then: function (fulfilled, rejected) {
+ process.nextTick(fulfilled);
+ }
+ };
+
+ it('should invoke the callback', function(done){
+ var test = new Runnable('foo', function(){
+ return fulfilledPromise;
+ });
+
+ test.run(done);
+ })
+ })
+
+ describe('when the promise is fulfilled with a value', function(){
+ var fulfilledPromise = {
+ then: function (fulfilled, rejected) {
+ process.nextTick(function () {
+ fulfilled({});
+ });
+ }
+ };
+
+ it('should invoke the callback', function(done){
+ var test = new Runnable('foo', function(){
+ return fulfilledPromise;
+ });
+
+ test.run(done);
+ })
+ })
+
+ describe('when the promise is rejected', function(){
+ var expectedErr = new Error('fail');
+ var rejectedPromise = {
+ then: function (fulfilled, rejected) {
+ process.nextTick(function () {
+ rejected(expectedErr);
+ });
+ }
+ };
+
+ it('should invoke the callback', function(done){
+ var test = new Runnable('foo', function(){
+ return rejectedPromise;
+ });
+
+ test.run(function(err){
+ err.should.equal(expectedErr);
+ done();
+ });
+ })
+ })
+ })
+
+ describe('when fn returns a non-promise', function(){
+ it('should invoke the callback', function(done){
+ var test = new Runnable('foo', function(){
+ return { then: "i ran my tests" };
+ });
+
+ test.run(done);
+ })
+ })
})
})