Questions tagged [sinon-chai]

Sinon–Chai provides a set of custom assertions for using the Sinon.JS spy, stub, and mocking framework with the Chai assertion library. You get all the benefits of Chai with all the powerful tools of Sinon.JS.

Extends with assertions for the mocking framework.

Github page

268 questions
0
votes
1 answer

testing promised service with Chai and Sinon

I'm stuck with testing promies in Chai and Sinon. Generally I got service with is wrapper for xhr request and it returns promises. I tried to test it like that: beforeEach(function() { server =…
cachaito
  • 343
  • 1
  • 6
  • 19
0
votes
1 answer

Sinon.stub getting called in test, but expect to be called statement fails

I have a stateless react component that has an onClick method that I'm trying to test is getting called. The way I'm doing it is to set a prop with a default value pointing towards the method that will be called in production, so that I can test the…
realisation
  • 475
  • 6
  • 19
0
votes
1 answer

sinon.spy(func) is not producing a called even when it is called

I have a test that is spying on a stubbed out method. The method is faking a dependency. I can verify the method is actually being called. I can even verify that it's being called with the expected arguments. However, the spy isn't providing a true…
Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
0
votes
1 answer

Testing to make sure that a function within a promise within a function is called?

I'm using Mocha, Chai, and Sinon to test my Angular code. I have some code in a function called update I need to test function update() //... Irrelevant code to the question asked DataService.getEventsData(query).then(function (res) { …
Oscar McCullough
  • 365
  • 4
  • 17
0
votes
2 answers

Stubbing PouchDB with Sinon failing

Im trying to stub a pouchDB 'put' function but in an invoked function but it is failing. my DB function- var PouchDB = require('pouchDB') var PendingDB = new PouchDB("") module.exports.addPendingRequest = function(doc, callback){ …
Badi8beach
  • 556
  • 2
  • 4
  • 18
0
votes
1 answer

AngularJS/Ionic/SinonChai - How to mock up the $ionicModal.fromTemplateUrl function

I am having trouble in my test for an ionic modal controller. The problem (or at least the problem I'm focusing on) is mocking up the $ionicModal.fromTemplateUrl function. According to ionic documentation, it's supposed to return a promise that…
0
votes
1 answer

Sinon stubbed function is not recognised by chai spy when asserting function call

I have two asynchronous functions that return bluebird promises: Async1: function() { return new Promise(function(resolve, reject) { execute(query) .then(function(resp) { resolve(resp); }) .catch(function(err) { …
JH95
  • 489
  • 1
  • 7
  • 24
0
votes
1 answer

karma-sinon-chai fails after moving to Windows

I have unit tests running under Karma, and am using the sinon-chai library. Everything was working fine on Mac, but now I have moved to Windows the following error is occuring: C:\Users\mchambe4\dev\simple\client>node ./node_modules/gulp/bin/gulp.js…
Mike Chamberlain
  • 39,692
  • 27
  • 110
  • 158
-1
votes
2 answers

How do I unit test using sinon?

A.js const func2 = () => 'world'; module.exports = {func2} Util.js const {func2} = require("./A"); const func1 = () => { return 'hello ' + func2(); // <= use the module } module.exports = { func1 } Util.test.js const sinon =…
Pradeep Poojari
  • 155
  • 1
  • 1
  • 9
-1
votes
1 answer

Unit tests for request-promise-native using Sinon

How can I write a unit test for this method? import { CoreOptions, UriOptions } from 'request'; import requestPromise from 'request-promise-native'; export class Client { public async post(request: CoreOptions & UriOptions) { return…
Darkin Rall
  • 377
  • 1
  • 4
  • 17
-1
votes
1 answer

How to address NodeJS's built-in functions with Sinon?

Using Sinon stubs, I have successfully stubbed functions along the project, using the traditional stubbing syntax: const permissionsStub = sinon.stub(invitation, 'update') sinon.assert.calledOnce(permissionsStub) Now I am trying to Stub a built-in…
StackMaster
  • 359
  • 1
  • 5
  • 22
-1
votes
1 answer

Why am I receiving an expectation error?

I have created a spec for my library to ensure that a value is emitted at a regular interval. I am using sinonjs and have created a callback as a spy. I am using the fake timer in sinonjs to simulate an extra two intervals of 10 seconds passed.…
-1
votes
1 answer

Sinon.js: spy empty callback

i'm trying to test callback functions with sinon.js handleLoginActions = function (callback) { ... if (callback) { callback() } .. } var loginCallbackStub =…
mauriblint
  • 1,802
  • 2
  • 29
  • 46
1 2 3
17
18