<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">Tests seem like a reasonable place to take a perf trade off though, right?<br><br><div id="AppleMailSignature">Mobile/terse. DYAC. </div><div><br>On Nov 20, 2017, at 10:29 AM, Tom Schuster <<a href="mailto:tom@schuster.me">tom@schuster.me</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">Please don't use proxies unnecessarily. They are bad for performance. <br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 20, 2017 at 5:05 PM, Joe Hildebrand <span dir="ltr"><<a href="mailto:jhildebrand@mozilla.com" target="_blank">jhildebrand@mozilla.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You could also potentially use a Proxy object:<br>
<br>
<a href="https://gist.github.com/hildjj/1ac6e3d52e4e0d23f6289d73c1840a5a" rel="noreferrer" target="_blank">https://gist.github.com/<wbr>hildjj/<wbr>1ac6e3d52e4e0d23f6289d73c1840a<wbr>5a</a><br>
<div><div class="h5"><br>
> On Nov 20, 2017, at 9:00 AM, Richard Newman <<a href="mailto:rnewman@mozilla.com">rnewman@mozilla.com</a>> wrote:<br>
><br>
> Are there alternative ways we could achieve the same without the (or with low) complexity/overhead?<br>
><br>
> If I'm understanding correctly what you're trying to do, the typical suggestion here is to not use global singletons. That way you don't need to dig into the guts of a globally visible object in order to test it; you can pass your own part-mocked Object instance into whatever mechanism is trying to call `Object.foo`.<br>
><br>
> In your `foo`/`bar` case, you'd pass a `MockObject` to `bar`, and verify that `MockObject.foo` was called. We do this all the time in codebases that use less dynamic languages (e.g., Fennec and Firefox for iOS).<br>
><br>
> This doesn't help you to test existing singleton-based JS code… but then, if that code is already using Object.freeze, then you already can't, and you'll be having to change _something_.<br>
><br>
> I mostly agree with Nicolas's sentiment; poking at the guts of code outside your own module (or even in your own module!) isn't really a kind of software development that I feel we should encourage. If we find that gut-poking is the only good way to write tests for a component, then I would rather we revisit the design of the component instead of making it mutable. Refactoring for testability is A-OK in my book.<br>
</div></div><span class="">> ______________________________<wbr>_________________<br>
> firefox-dev mailing list<br>
> <a href="mailto:firefox-dev@mozilla.org">firefox-dev@mozilla.org</a><br>
> <a href="https://mail.mozilla.org/listinfo/firefox-dev" rel="noreferrer" target="_blank">https://mail.mozilla.org/<wbr>listinfo/firefox-dev</a><br>
<br>
</span>—<br>
<span class="HOEnZb"><font color="#888888">Joe Hildebrand<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
______________________________<wbr>_________________<br>
firefox-dev mailing list<br>
<a href="mailto:firefox-dev@mozilla.org">firefox-dev@mozilla.org</a><br>
<a href="https://mail.mozilla.org/listinfo/firefox-dev" rel="noreferrer" target="_blank">https://mail.mozilla.org/<wbr>listinfo/firefox-dev</a><br>
</div></div></blockquote></div><br></div>
</div></blockquote></body></html>