Trying to test setInterval function in javascript and get this error: Attempted to wrap undefined property function updateViz() { #1192

Open
sensorhound-nan opened this Issue Nov 17, 2016 · 1 comment

Projects

None yet

2 participants

@sensorhound-nan
sensorhound-nan commented Nov 17, 2016 edited

I am using QUnit to do unit test for the javascript. I need to use sinon spy to test the setInterval function. I want to make sure that the function is called once after some time interval.

Things I need to test:
function bigVizInit() {
...
setInterval(updateViz, 5000);
...
}

And updateViz is a function like this:
function updateViz() {
...
}

The code I wrote for testing is like this:
QUnit.test("bigVizInit", function( assert ) {
...
var spy = sinon.spy(window, updateViz);
var done = assert.async();
setTimeout( function() {
assert.ok(spy.calledOnce);
done();
}, 6000);
...
});

And I got this Error: Attempted to wrap undefined property function updateViz().

As we can see, here the updateViz is a standalone function, so I use window as a wrapper for it.
I have also tried:
var spy = sinon.spy(updateViz);
And then the spy.calledOnce is false.

Someone has the same problem?

@sensorhound-nan sensorhound-nan changed the title from Trying to test setInterval function in javascript and get this error: to Trying to test setInterval function in javascript and get this error: Attempted to wrap undefined property function updateViz() { Nov 17, 2016
@mroderick
Contributor

Fill in the issue template, so we can determine if this is a bug in Sinon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment