I am trying to climb the learning curve on using require.js/mocha/chai/sinon with backbone apps. When I run this test:
define([
"chai",
"sinon"
], function(chai, sinon){
var expect = chai.expect;
describe("Trying out the test libraries", function(){
describe("Chai", function(){
it("should be equal using 'expect'", function(){
expect(hello()).to.equal("Hello World");
});
});
describe("Sinon.JS", function(){
it("should report spy called", function(){
var helloSpy = sinon.spy(window, "hello");
expect(helloSpy.called).to.be.false;
hello();
expect(helloSpy.called).to.be.true;
hello.restore();
});
});
});
});
I get TypeError: Object #<Object> has no method 'spy'
on the line where helloSpy is defined. Why? Note that the first test passes.
Here is the full project:
https://github.com/ErikEvenson/spa-testing-study/tree/bcc5b71b3b6f8b24f7e8d01673b50682498ee1b2.
Take care to use that particular commit.
The problem here turns out to be that the bower repository for sinon is unusable as is per this issue. Sinon has to be built first and doing bower install sinon
just pulls the Sinon.JS repo down. Using bower install sinonjs
instead of bower install sinon
works, but gives an earlier version number.
From @Erik link.
install --save-dev sinonjs-built
This will get you build version of sinon.
a another bower version ( as @Erik suggested above) may be found in https://github.com/blittle/sinon.js
one can install it via
install --save-dev sinonjs
from sinon github
:
Important: AMD needs pre-built version Sinon.JS as source doesn't work with AMD loaders (when they're asynchronous, like loading via script tags in the browser). For that you will have to use a pre-built version. You can either build it yourself or get a numbered version from http://sinonjs.org.
You can edit the bower.json
file. and instead of writing version just pass a url
for the file
i.e
[...]
"devDependencies": {
"chai": "~1.10.0",
"sinon": "http://sinonjs.org/releases/sinon-1.12.2.js#*",
},
[...]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With