Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2026 - Updated to support spying all methods on an object to similar …
…to stub capabilities
- Loading branch information
White, Ben
committed
May 22, 2019
1 parent
ff505fc
commit 181dcdd
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use strict"; | ||
|
||
var getPropertyDescriptor = require("./util/core/get-property-descriptor"); | ||
var walk = require("./util/core/walk"); | ||
|
||
function spyEntireObject(spy, object) { | ||
walk(object || {}, function(prop, propOwner) { | ||
// we don't want to spy things like toString(), valueOf(), etc. so we only spy if the object | ||
// is not Object.prototype | ||
if ( | ||
propOwner !== Object.prototype && | ||
prop !== "constructor" && | ||
typeof getPropertyDescriptor(propOwner, prop).value === "function" | ||
) { | ||
spy(object, prop); | ||
} | ||
}); | ||
|
||
return object; | ||
} | ||
|
||
module.exports = spyEntireObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters