@uifabric/utilities
Version:
Fluent UI React utilities for building components.
23 lines • 1.07 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Injects a function call prior to running a method for a component
* rendered using enzyme deep rendering.
* @param wrapper - The enzyme deep rendering wrapper object to modify
* @param methodName - The name of the method to modify on the wrapper
* @param fn - The function to run prior to the call of the original method
*/
function injectWrapperMethod(wrapper, methodName, fn) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var originalMethod = wrapper.instance()[methodName];
if (typeof originalMethod !== 'function') {
throw new Error("Tried to override the method " + methodName + " on a ReactWrapper that does not have that function");
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
wrapper.instance()[methodName] = function (prevProps) {
fn();
originalMethod.call(this, prevProps);
};
}
exports.injectWrapperMethod = injectWrapperMethod;
//# sourceMappingURL=injectWrapperMethod.js.map
;