You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
@@ -163,29 +153,27 @@ console.log("Hello"); // ouch, that won't work. console is undefined at this p
163
153
varconsole=null;
164
154
```
165
155
166
-
###leaks
167
-
Leaks are executed at the end of the module. If a`var` is undefined at this point you
168
-
won't be able to access the leak (because`undefined`-values are[copied by value](http://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language)).
169
-
A good approach to this is:
156
+
###Leaks are executed at the end of the module.
157
+
All variables, that are[copied by value](http://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language)
158
+
will not be updated anymore.
159
+
160
+
A good approach to solve this would be:
170
161
171
162
```javascript
172
163
var myLeaks= {};
173
164
174
165
module.exports=function (someValue) {
175
166
myLeaks.someValue= someValue;
176
167
};
177
-
178
-
// End of module ///////////////
179
-
// rewire will inject here
180
-
module.exports.__= {myLeaks: myLeaks};
181
168
```
182
169
170
+
And then:```rewire("myModuleA.js", null, null, ["myLeaks"]);```
171
+
183
172
Because```myLeaks``` is defined at the end of the module, you're able to access the leak object and all leaks that
184
-
are attached to it later during runtime. Because myLeaks is not exposed under regular circumstances your
185
-
module interface stays clean.
173
+
are attached to it later during runtime.
186
174
187
-
###reset
188
-
You should call this before every unit test to ensure a clean test environment.
175
+
###Call rewire.reset() after every unit test
176
+
All```require()```s will now return the original module again.