Просмотр исходного кода

Test failure when wrapped method is not async/callback

Shane Kilkelly 9 лет назад
Родитель
Сommit
772f950d7c

+ 15 - 0
libraries/metrics/test/unit/coffee/timeAsyncMethodTests.coffee

@@ -87,3 +87,18 @@ describe 'timeAsyncMethod', ->
 			expect(badWrap).to.throw(
 				/^.*expected object property 'DEFINITELY_NOT_A_REAL_METHOD' to be a function.*$/
 			)
+
+	describe 'when the wrapped function is not using a callback', ->
+		beforeEach ->
+			@testObject.nextNumber = (n) ->
+				return n+1
+
+		it 'should throw an error', ->
+			@timeAsyncMethod @testObject, 'nextNumber', 'test.nextNumber'
+			badCall = () =>
+				@testObject.nextNumber 2
+			expect(badCall).to.throw(
+				/^.*expected wrapped method 'nextNumber' to be invoked with a callback.*$/
+			)
+
+

+ 18 - 1
libraries/metrics/test/unit/js/timeAsyncMethodTests.js

@@ -108,7 +108,7 @@
         })(this));
       });
     });
-    return describe('when the wrapper cannot be applied', function() {
+    describe('when the wrapper cannot be applied', function() {
       beforeEach(function() {});
       return it('should raise an error', function() {
         var badWrap;
@@ -120,6 +120,23 @@
         return expect(badWrap).to["throw"](/^.*expected object property 'DEFINITELY_NOT_A_REAL_METHOD' to be a function.*$/);
       });
     });
+    return describe('when the wrapped function is not using a callback', function() {
+      beforeEach(function() {
+        return this.testObject.nextNumber = function(n) {
+          return n + 1;
+        };
+      });
+      return it('should throw an error', function() {
+        var badCall;
+        this.timeAsyncMethod(this.testObject, 'nextNumber', 'test.nextNumber');
+        badCall = (function(_this) {
+          return function() {
+            return _this.testObject.nextNumber(2);
+          };
+        })(this);
+        return expect(badCall).to["throw"](/^.*expected wrapped method 'nextNumber' to be invoked with a callback.*$/);
+      });
+    });
   });
 
 }).call(this);