Multiple assignments of sinon.spy()

315 views
Skip to first unread message

Lokesh Yadav

unread,
Aug 27, 2013, 1:07:47 AM8/27/13
to sin...@googlegroups.com
Hi there,

Being a newbie to Sinon, i am trying sinon with mocha to put assertions on specific function calls. 

    describe("Test Suite", function() {
        beforeEach(function() {
            spy = sinon.spy(window._gaq, 'push');
        });

        afterEach(function() {
            spy.restore();
        });

        it ("Track link"), function() {
                link = $('*[data-type]');
                link.click();
                sinon.assert.called(spy);            
              }); 
            })(i)
        }
    });

Now, i am trying to put one more assertion for function call. For that one more spy() assignments is placed inside beforeEach(). But after this, the code snippet is not working. 
....
beforeEach(function() {
    spy = sinon.spy(window._gaq, 'push');
    spy = sinon.spy(window, 'trackItems');
});
.....

Please advice how can i set mulitple spy assignments. Any help would be a life savor for me. 

Regards,
Lokesh


Maximilian Antoni

unread,
Aug 27, 2013, 2:30:50 AM8/27/13
to sin...@googlegroups.com
There's two things you can do:

1. Use different names for your spy variables (you are using "spy" twice)
2. Refer to the spied functions directly, e.g.  sinon.assert.called(_gaq);

Cheers
Max

--
You received this message because you are subscribed to the Google Groups "Sinon.JS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sinonjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Lokesh Yadav

unread,
Aug 27, 2013, 2:53:05 AM8/27/13
to sin...@googlegroups.com
thanks a lot Max, given first solution[different variable names] worked for me. Will definitely give a try to the second one.

thanks a ton again for your help.


Regards
Lokesh
Reply all
Reply to author
Forward
0 new messages