Questions tagged [sinon]

Sinon is a mocking framework for JavaScript, which can create spies, stubs and mocks.

Sinon is to create test spies, stubs and mocks that can be used with any JavaScript unit testing framework. It is also shipped as part of the Buster.JS unit test framework.

2840 questions
1
vote
1 answer

Sinon: spy on jquery function call

How can I check if $("#myElement").change(); is called on? I've tried spy = sinon.spy($("#myElement"), "change"); And then expect(spy).toHaveBeenCalled();
Eccentrikit
  • 123
  • 6
1
vote
1 answer

How to mock a glob call in Node.js

I'm using Mocha, Chai and Sinon JS to write Unit Tests for my Node.js application. Here is the module I want to test: var glob = require('glob'); var pluginInstaller = require('./pluginInstaller'); module.exports = function(app, callback) { …
Tineler
  • 253
  • 3
  • 17
1
vote
0 answers

sinon spy is not fired inside the mongodb findOne callback

I am trying to test a similar code to this testFind = (cb) -> cb() wrapper = (fn) -> (req, mongodb) -> users = mongodb.db.collection("user") # fired here fn req, mongodb testFind (err, user) -> #fired here fn req,…
ash
  • 101
  • 1
  • 7
1
vote
0 answers

Inject javascript to mock data

Is there a way to import an existing file and inject javascript into the head/body? I want to use sinon to fake a server but not for unit tests. Currently I need to access an API that only runs privately on my work servers. When I am home I would…
David Pullar
  • 706
  • 6
  • 18
1
vote
2 answers

sinon server.autoRespond

I'm learning testing, so I construct this simple example, using karma,karma-jasmine and sinon.js: I have got an ajax Request, on success it sets an global variable. With the sinon fakeServer I fake the respond, everything is fine if I fire the…
kufufra
  • 36
  • 1
  • 8
1
vote
0 answers

Using QUnit and sinon.spy, how can I access my spy within an async callback?

I am new to QUnit and sinon.js and working to build tests for an ember-cli package. I am having problems getting sinon.spy(Ember.run, 'later') to work with the code below. inside the callback Ember.run.later is not being spied / has no .getCalls()…
erichonkanen
  • 199
  • 1
  • 7
1
vote
0 answers

Unit testing angularjs with mocha/chai should.have.been.called not working

The following test passes whether my expect statement is expect(propertyFactory.readProperty).should.have.been.called; or expect(propertyFactory.readProperty).should.have.not.been.called; I've tried this with or without the sinon…
ThinkingInBits
  • 10,792
  • 8
  • 57
  • 82
1
vote
2 answers

Sinonjs fakeserver - multiple ajax calls

I use QUnit together with sinon. How can I make sinon's fakeserver respond to chained ajax called made from the same method? module('demo', { beforeEach: function(){ this.server = sinon.fakeServer.create(); }, afterEach:…
filur
  • 2,116
  • 6
  • 24
  • 47
1
vote
1 answer

First async unit test with Mocha and Sinonjs

I m actually using a micro framework created by my society in which we use Mongoose. To manage the mongoose object, we created a modelfactory, that returns us a model corresponding to the mongoose name object. Actually, I m working on an…
mfrachet
  • 8,772
  • 17
  • 55
  • 110
1
vote
0 answers

How do you catch parameters in httpBackend.expectPOST?

AngularJS / Typescript/ AMD / RequireJS / Jasmine / Karma / Sinon I have an AngularJS custom logging service that builds a private internal queue of log messages. This internal queue only counts messages that are not of type debug in its queue. At…
Paul
  • 11
  • 2
1
vote
2 answers

'then' function is not never getting called by Mocha for assertion checking

I have written the following test case in Mocha, where the my code uses Q module. var expect = require("chai").expect; var utils = require("../Utils.js"); var utils1 = require("../a.js"); var sinon = require('sinon'); var request =…
Prachi g
  • 849
  • 3
  • 9
  • 23
1
vote
1 answer

Mocking a method's response using SinonJS

I am very new to testing world. I have a following function: exports.get = function (para1) { var response = querySys(para1); response.in = 1; return response; } I want to mock the result of querySys method. I want it to return {in: 0,…
Prachi g
  • 849
  • 3
  • 9
  • 23
1
vote
1 answer

How to stub angular-translate promise and verify actions in 'then'

I'm translating an app with angular-translate, but having trouble fixing up my test suite. Before - controller looked like: $scope.$on 'new-fetch-controller:step-2', -> if EmailUtils.validate(self.contributorEmail) ToastService.show "Did you…
bikezilla
  • 21
  • 2
1
vote
1 answer

unit test for angular responseError interceptor with 'notify' promise

I have angular responseError interceptor, which implements logic of resending request to server if a previous attempt was unsuccessful. Moreover the interceptor returns 'notify' promise to keep in touch about current status. return { …
Gleb Vinnikov
  • 458
  • 4
  • 13
1
vote
0 answers

Test a function which uses document properties in qunit

I have a function like this which I would like to write a unit test for : function A () { var x = document.referrer; //Do something with 'a' } I would like to write a unit test, to test this function. I'm using QUnit with sinon.js for…
Deepak
  • 353
  • 5
  • 14
1 2 3
99
100