Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Made templates able to have a preset return value

  • Loading branch information...
commit 21b3ab49b1d590f81f4c8f27cc738498c4238702 1 parent 50c6050
authored July 31, 2012
9  lib/pretendr.js
@@ -56,6 +56,7 @@ module.exports = function (o) {
56 56
 	pretendrFunction = function () {
57 57
 		var fake,
58 58
 			pretendrObj,
  59
+			templateReturnValue,
59 60
 			returnValue,
60 61
 			template;
61 62
 		pretendrObj = {
@@ -69,6 +70,11 @@ module.exports = function (o) {
69 70
 			},
70 71
 			template : function (t) {
71 72
 				template = t;
  73
+				return {
  74
+					returnValue : function (r) {
  75
+						templateReturnValue = r;
  76
+					}
  77
+				};
72 78
 			},
73 79
 			mock : function () {
74 80
 				var call,
@@ -92,6 +98,9 @@ module.exports = function (o) {
92 98
 					call.returned = fake.apply(this, arguments);
93 99
 				} else if (template) {
94 100
 					call.pretendr = module.exports(template);
  101
+					if (templateReturnValue) {
  102
+						call.pretendr.returnValue(templateReturnValue);
  103
+					}
95 104
 					call.returned = call.pretendr.mock;
96 105
 				} else {
97 106
 					call.returned = returnValue;
11  test/spec.js
@@ -191,6 +191,17 @@ describe("pretendr", function () {
191 191
                 expect(instance).to.be.a(this.p.mock);
192 192
             });
193 193
         });
  194
+		describe("#template", function () {
  195
+			it("should be able to define returnValues", function () {
  196
+				var m = this.pretendr(function () {}),
  197
+					res,
  198
+					t;
  199
+				t = m.template(function () {});
  200
+				t.returnValue('a');
  201
+				res = m.mock();
  202
+				expect(res()).to.equal('a');
  203
+			});
  204
+		});
194 205
         describe("with properties", function () {
195 206
             it("should mock the properties", function () {
196 207
                 var fn = function () {};

0 notes on commit 21b3ab4

Please sign in to comment.
Something went wrong with that request. Please try again.