zjsunit: Prevent mocking functions with with_field_rewire.

This commit is contained in:
Steve Howell 2022-01-08 15:27:55 +00:00 committed by Tim Abbott
parent e9640ceb16
commit 047a119d46
1 changed files with 4 additions and 0 deletions

View File

@ -347,6 +347,10 @@ exports.with_field_rewire = function (obj, field, val, f) {
// as exporting a helper function for tests from the module
// containing the function you need to mock.
if (typeof val === "function") {
throw new TypeError("Please try to avoid mocking here, or use override_rewire.");
}
const old_val = field in obj ? obj[field] : obj.__GetDependency__(field);
try {
obj.__Rewire__(field, val);