tag:blogger.com,1999:blog-185306606329902270.post781960501105079875..comments2022-10-03T01:33:49.782-07:00Comments on Drew's Prog 'Blog: Stubbing Node Code for TDDDrew Millerhttp://www.blogger.com/profile/03573525144205530731noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-185306606329902270.post-86220911178244949972010-05-20T09:16:03.760-07:002010-05-20T09:16:03.760-07:00From another angle, the testing that I've been...From another angle, the testing that I've been doing on other, webpage-based stuff, is using heavy DI. This simulates better the node experience, especially as it relates to the eventing mechanism. Modules are still an interesting one, though. I wonder if it would be worth putting parameter-based stubs on require(). Hmm....Corey Haineshttps://www.blogger.com/profile/06863615802688642075noreply@blogger.comtag:blogger.com,1999:blog-185306606329902270.post-686523667237470432010-05-20T09:14:29.729-07:002010-05-20T09:14:29.729-07:00The spy approach boiled naturally out of the way m...The spy approach boiled naturally out of the way my js testing was going. I like it a lot more than a mock-style one.<br /><br />Yeah, the common.js module system is a bit different. I'll be looking to use spies.js when I start doing more isolation testing in node, so I'll see what it will take to change it (if it is worth it).<br /><br />For now, I haven't started testing the web stuff, which is where I'll be doing a lot of isolation, I'm only testing more straight-forward stuff, as you can see in my repo going through the 'Purely Functional Data Structures' book: http://vurl.me/QSQCorey Haineshttps://www.blogger.com/profile/06863615802688642075noreply@blogger.comtag:blogger.com,1999:blog-185306606329902270.post-30566282145793498702010-05-20T08:56:19.928-07:002010-05-20T08:56:19.928-07:00Thanks for the note, Corey.
Looking at spies.js,...Thanks for the note, Corey. <br /><br />Looking at spies.js, it's not clear to me whether it would work with Node's (really CommonJS') modules specification. It looks like (after an admittedly brief glance) you're always stubbing on objects you create and pass to the code-to-test. With modules, you won't be creating the objects in test code, unless you broker with some sort of dependency injection. I'm used to Ruby's meta-prog, which allowed me to skip DI in my test code, but I couldn't find a way to do similar things in Node. And, now, I actually like the locality and terseness I have with the DI approach.<br /><br />One way in which spies.js might be nice is keeping the assertions out of the stubs. With Node, because so much of the code relies on callbacks, I've found myself peppering my stubs with assertions (and with the finished signal, since the callbacks are often asynchronous). At first, the purist in me was appalled by this, but now I'm actually starting to like it. It's very readable, compact, and I haven't missed a stubbing library, yet. <br /><br />But, using a spy-oriented stubbing framework is definitely a good approach to keep the assertions in a more preferable 3A pattern.Drew Millerhttps://www.blogger.com/profile/03573525144205530731noreply@blogger.comtag:blogger.com,1999:blog-185306606329902270.post-79512702445168078202010-05-20T06:14:12.283-07:002010-05-20T06:14:12.283-07:00I haven't tried it with node, yet, but I'v...I haven't tried it with node, yet, but I've been having good luck stubbing (and spying) with my spies.js framework. (shameless plug). :) I'm working with node now, so I'll see how it goes with the modules and what might need to be altered with it.<br /><br />http://github.com/coreyhaines/spies.jsCorey Haineshttps://www.blogger.com/profile/06863615802688642075noreply@blogger.com