Using sinon.js with streamline

55 views
Skip to first unread message

Alex May

unread,
Feb 22, 2014, 3:59:21 PM2/22/14
to stream...@googlegroups.com
Hello,

I'm working on a project using streamline, and just ran into an interesting issue when using sinon.js stub library (http://sinonjs.org/docs/#stubs) in a mocha test. If I attempt to stub a method on a collaborator's function that is managed by streamline, the stub never returns. I have attached an example file that shows this issue. To run this, you will need to do the following:

npm install -g mocha streamline
npm install sinon should
mocha --compilers _js:streamline/register exampleTest._js

I'm curious if anyone else has run into this, and if so, what their workarounds have been.

Thanks!

exampleTest._js

Bruno Jouhier

unread,
Mar 29, 2014, 12:01:06 PM3/29/14
to stream...@googlegroups.com
Hello Alex,

The problem comes from the fact that sinon's stubbing is not aware that the function is asynchronous. It calls it like a synchronous function (with apply) when it should call it as an asynchronous function (with streamline's apply_ extension - see https://github.com/Sage/streamlinejs/blob/master/lib/compiler/builtins.md#function-functions).

I saw some async APIs in sinon's documentation. You should try http://sinonjs.org/docs/ (stub.callsArgWithAsync). You should use these Async APIs with streamline functions that have an _ parameter. I don't know how tricky this will be because I've never used sinon.

Bruno
Reply all
Reply to author
Forward
0 new messages