Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed mock property from template objects

No real problem with having it, but it just seems cleaner to remove it.
  • Loading branch information...
commit 3f0b9db655cd1a6afc0f0210a5ac4f2819507072 1 parent 04e4d80
@nathanmacinnes authored
Showing with 16 additions and 8 deletions.
  1. +11 −7 lib/pretendr.js
  2. +5 −1 test/spec.js
View
18 lib/pretendr.js
@@ -18,7 +18,7 @@ nonPrimitive = function (o) {
return typeof o === 'object' || typeof o === 'function';
};
-makePretendr = function (descriptor, mock) {
+makePretendr = function (descriptor, mock, asTemplate) {
var ins = [],
outs = [],
subMakePretendr;
@@ -56,10 +56,10 @@ makePretendr = function (descriptor, mock) {
};
setTemplate = function (o) {
o = o || {};
- if (o.hasOwnProperty('mock') && o.hasOwnProperty('clone')) {
+ if (o.hasOwnProperty('clone')) {
attributes.template = o.clone();
} else {
- attributes.template = makePretendr(o);
+ attributes.template = makePretendr(o, null, true);
}
return attributes.template;
};
@@ -98,14 +98,18 @@ makePretendr = function (descriptor, mock) {
baseObj.template = setTemplate;
}
- // create the mocks, either based on the object passed in (for creating
- // instances) or using the makeMock function
- baseObj.mock = mock || makeMock(descriptor, baseObj, attributes);
+ if (!asTemplate) {
+ // create the mocks, either based on the object passed in (for
+ // creating instances) or using the makeMock function
+ baseObj.mock = mock || makeMock(descriptor, baseObj, attributes);
+ }
if (nonPrimitive(descriptor)) {
for (i in descriptor) {
if (descriptor.hasOwnProperty(i)) {
baseObj[i] = subMakePretendr(descriptor[i]);
- baseObj.mock[i] = baseObj[i].mock;
+ if (!asTemplate) {
+ baseObj.mock[i] = baseObj[i].mock;
+ }
}
}
}
View
6 test/spec.js
@@ -368,6 +368,10 @@ describe("pretendr", function () {
mockObj.template(templateDescriptor);
}).to.not.throwError();
});
+ it("should not have a mock property", function () {
+ var template = this.pretendr(function () {}).template({});
+ expect(template).to.not.have.property('mock');
+ });
});
describe("array", function () {
beforeEach(function () {
@@ -387,4 +391,4 @@ describe("pretendr", function () {
expect(this.pretendrResult[2].calls).to.have.length(1);
});
});
-});
+});
Please sign in to comment.
Something went wrong with that request. Please try again.