Intermittent errors using sinon with Karma, RequireJS and multiple browsers

402 views
Skip to first unread message

Dani

unread,
Aug 15, 2014, 1:29:09 PM8/15/14
to sin...@googlegroups.com
I'm using RequireJS, and writing unit tests with Mocha, Chai and Sinon. Then using Karma to run the tests.

If running only in one browser, then it works. For example, karma.conf.js would have:
browsers: ['Chrome'],

But when running multiple browsers, for example:
browsers: ['Chrome', 'Firefox'],

Then the tests fail intermittently with various sinon errors such as:
 sandbox.stub is not a function

Or
 TypeError: sinon.spy is undefined
  at c:/projects/myproject/bower_components/sinon/lib/sinon/mock.js:172

They typically work in one browser and fail in the other, it varies.

Does anyone know what causes this or how to fix it?

bower.json dev dependencies:
 "requirejs": "2.1.11",
 "chai": "~1.9.1",
 "sinon": "~1.10.3",

package.json karma and mocha dev dependencies:
    "karma": "^0.12.1",
    "karma-chrome-launcher": "^0.1.4",   
    "karma-firefox-launcher": "^0.1.3",
    "karma-mocha": "^0.1.6",
    "karma-requirejs": "^0.2.1",
    "mocha": "^1.20.1"

Travis Kaufman

unread,
Aug 15, 2014, 6:41:28 PM8/15/14
to sin...@googlegroups.com
I know this doesn't directly answer your question (which I apologize for), but I've never had much luck using sinon from bower. I usually opt for the pre-built version: 
http://sinonjs.org/releases/sinon-1.10.3.js

All the components are bundled into one script and you can just drop it into your karma.conf.js and be on your way.

Hope this helps!

--
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/d/optout.


--
Travis Kaufman
travis....@gmail.com

Jonathon Creenaune

unread,
Aug 15, 2014, 6:54:11 PM8/15/14
to sin...@googlegroups.com

In my projects I'm including sinon via a karma plugin https://github.com/yanoosh/karma-sinon rather than including via bower. This works for me in multiple browsers ... which for me is chrome+phantomjs not chrome+firefox, so ymmv.

Dani

unread,
Aug 18, 2014, 7:06:19 AM8/18/14
to sin...@googlegroups.com
After some research, found that the bower package doesn't work properly. The download version from sinonjs.org does work.
The other thing is couldn't get it working as a RequireJS dependency, it only seems to work properly as a global.
So now its working.

thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to sinonjs+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Travis Kaufman
travis....@gmail.com

Reply all
Reply to author
Forward
0 new messages