Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1936: Make the spy functions non enumerable so that printing it is more concise #1941

Merged
merged 1 commit into from Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/sinon/spy.js
Expand Up @@ -217,9 +217,9 @@ var spyApi = {
var length = spyLength || funk.length;
var proxy = createProxy(funk, length);

extend(proxy, spy);
extend.nonEnum(proxy, spy);
delete proxy.create;
extend(proxy, funk);
extend.nonEnum(proxy, funk);

proxy.resetHistory();
proxy.prototype = funk.prototype;
Expand Down
50 changes: 39 additions & 11 deletions lib/sinon/util/core/extend.js
Expand Up @@ -51,24 +51,15 @@ var hasDontEnumBug = (function() {
return join(result, "") !== "0123456789";
})();

/* Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will
* override properties in previous sources.
*
* target - The Object to extend
* sources - Objects to copy properties from.
*
* Returns the extended target
*/
module.exports = function extend(target /*, sources */) {
var sources = slice(arguments, 1);
function extendCommon(target, sources, doCopy) {
var source, i, prop;

for (i = 0; i < sources.length; i++) {
source = sources[i];

for (prop in source) {
if (hasOwnProperty(source, prop)) {
target[prop] = source[prop];
doCopy(target, source, prop);
}
}

Expand All @@ -80,4 +71,41 @@ module.exports = function extend(target /*, sources */) {
}

return target;
}

/** Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will
* override properties in previous sources.
*
* @arg {Object} target - The Object to extend
* @arg {Object[]} sources - Objects to copy properties from.
*
* @returns {Object} the extended target
*/
module.exports = function extend(target /*, sources */) {
var sources = slice(arguments, 1);

return extendCommon(target, sources, function copyValue(dest, source, prop) {
dest[prop] = source[prop];
});
};

/** Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will
* override properties in previous sources. Define the properties as non enumerable.
*
* @arg {Object} target - The Object to extend
* @arg {Object[]} sources - Objects to copy properties from.
*
* @returns {Object} the extended target
*/
module.exports.nonEnum = function extendNonEnum(target /*, sources */) {
var sources = slice(arguments, 1);

return extendCommon(target, sources, function copyProperty(dest, source, prop) {
Object.defineProperty(dest, prop, {
value: source[prop],
enumerable: false,
configurable: true,
writable: true
});
});
};