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
0 answers

Sinon stub is not tracking consecutive methods invocation of the app

I'm trying to make a basic integration test using Karma, Sinon and Mocha, but it's not return the expected result. The application has a simple flow: todo.init --> calls todo.api.sendRequest({options Object}, callback) --> calls…
Elvio Cavalcante
  • 476
  • 5
  • 10
1
vote
0 answers

Mocking/Intercepting JSONP requests coming from DOM script injection

I am currently setting up tests that utilize OpenLayers and I would like to be able to mock requests to services like Bing Maps in Karma unit tests. I've tried to use Sinon to mock XHR requests but realized it is generating these requests by…
Darren Reid
  • 2,322
  • 20
  • 25
1
vote
1 answer

Sinon spy on WebSocket

I am trying to spy on WebSocket construction using sinon.js with this code (requirebin): sinon = require('sinon'); sinon.spy(window, 'WebSocket'); // throws an error (see console) new window.WebSocket("ws://example.com"); In Chrome it fails with…
artemave
  • 6,786
  • 7
  • 47
  • 71
1
vote
1 answer

Targeting nested method with sinon and proxyquire

For the following snippet of nodejs code, how would I stub the send method using proxyquire and sinon, given that this belongs to file index.js? I have tried many ways but constantly get errors. var emailjs =…
hyprstack
  • 4,043
  • 6
  • 46
  • 89
1
vote
0 answers

Javascript unit testing, force error in sinon stub callback

I am trying to test one last bit of this function I cannot seem to hit correctly. Here is the function CrowdControl.prototype.get = function(callback) { var options = this.optionsFor('GET'); return q.Promise(function(resolve, reject) { callback…
ajmajmajma
  • 13,712
  • 24
  • 79
  • 133
1
vote
1 answer

sinon stubs not working in nodejs tests

I am writing the tests for the Invoicer module. I am having two issues with my tests. The first one is that the emails are still being sent despite having stubbed the emailjs module (first test) and the second issue is that my second test timesout…
hyprstack
  • 4,043
  • 6
  • 46
  • 89
1
vote
1 answer

How To Test route.navigate on Backbone View

I'm currently developing a Backbone.js application which uses the Mocha, Chai, and Sinon libraries for testing. I'm struggling to code the following test: When a user clicks a button it should redirect the user to home. Here's how the view looks…
Diego Castillo
  • 175
  • 1
  • 15
1
vote
1 answer

How to fake Bluebird's timers in tests?

I have a function which makes use of Bluebird's Promise.delay() method to recursively check on the status of a long-running task every 5 seconds: waitForLongRunningTask: function (taskId) { return checkTaskStatus(taskId) .then(function (result)…
blah238
  • 1,796
  • 2
  • 18
  • 51
1
vote
2 answers

How to stub backbone models constructor?

Lets say I have a custom backbone model. var model = Backbone.Model.extend({ initialize: function(parameters) { var object = { key: parameters.key }; this.callMethod(); this.collection = new…
DasBoot
  • 469
  • 6
  • 17
1
vote
1 answer

Testing method called on Sinon.js spy

I am using SinonJS to test that my controller calls methods in my view. I want to test that the addSeat method is called with a value of testSeat. My best effort is what is in the code below but I am getting an error. I want to be able to test this…
ThomYorkkke
  • 2,061
  • 3
  • 18
  • 26
1
vote
2 answers

How can I structure a mocha unit test that involves promises and third party NPM modules?

The code I am trying to test is: exports.hasTokenOrApi = (req, res, next) -> if not req.headers?.authorization return res.status(403).end() new Promise (resolve, reject) -> if req.headers.authorization.length is 32 # We are using…
Shamoon
  • 41,293
  • 91
  • 306
  • 570
1
vote
1 answer

Sinon js call for PUT or POST methods

I am using sinon js in my project for fake server call. Its working fine for GET calls but I have a scenario in which I want to mock a server with PUT or POST call. I am doing it in this way: server = sinon.fakeServer.create();…
Emmad Zahid
  • 438
  • 6
  • 15
1
vote
2 answers

Restoring an anonymous sinon.stub

I'm using Qunit to unit test some jQuery. For some of my tests, I want to stub out a function (called cycle()), and for later tests, I want to call the original function. I've organised and separated these in modules, but the stub is still in place.…
Chris McGinlay
  • 285
  • 2
  • 10
1
vote
1 answer

Stub a dependency function in sinon

I am using intern as testing framework and sinon for mocking the data. I dont want to hit the server for http requests during unit tests. So I have created a module that returns the data in deferred.promise as shown below: define(["require", ..],…
1
vote
1 answer

Unit Testing a service with $http and $q using mocha, chai and sinon

I have this function and need test it using mocha, chai and sinon. This is my code: service-wiki-pelis.js 'use strict' var WikiService = function($http,$q){ return { getMovies: getMovies } function getMovies() { var…
1 2 3
99
100