UNPKG

1.29 kBTypeScriptView Raw
1declare namespace RewireInterfaces {
2 interface RewiredModule {
3 /**
4 * Takes all enumerable keys of obj as variable names and sets the values respectively. Returns a function which can be called to revert the change.
5 */
6 __set__(obj: { [variable: string]: any }): () => void;
7 /**
8 * Sets the internal variable name to the given value. Returns a function which can be called to revert the change.
9 */
10 __set__(name: string, value: any): () => void;
11 /**
12 * Returns the private variable with the given name.
13 */
14 __get__<T = any>(name: string): T;
15 /**
16 * Returns a function which - when being called - sets obj, executes the given callback and reverts obj. If callback returns a promise, obj is only reverted after
17 * the promise has been resolved or rejected. For your convenience the returned function passes the received promise through.
18 */
19 __with__(obj: { [variable: string]: any }): (callback: () => any) => any;
20 }
21}
22
23/**
24 * Returns a rewired version of the module found at filename. Use rewire() exactly like require().
25 */
26declare function rewire<T = { [key: string]: any }>(filename: string): RewireInterfaces.RewiredModule & T;
27export = rewire;