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

Sinon stub method calling from another file

I'm trying to set up unit tests in my project. For that, I use mocha chai and sinon librairies. I'm using a NodeJs server version 8. Versions : Sinon : "7.1.0" Mocha: "5.1.0" Chai: "4.2.0" I'd like to stub a method which is declared in another file.…
Hurobaki
  • 3,728
  • 6
  • 24
  • 41
0
votes
2 answers

sinon stubbed class not found

I started to write unit test cases using sinon and facing the following problem. myfile.js module.exports = class A{ constructor(classB_Obj){ this.classBobj = classB_Obj; classBobj.someFunctionOfClassB(); // error coming here …
Klose
  • 323
  • 5
  • 17
0
votes
1 answer

Issue when testing function with sinon and chai

I am trying to start using testing on my projects, and some things I am able to test properly but others don't. Here is the function I want to test. exports.rateReview = async (req, res, next) => { try { const review = await…
Maxi Bisurgi
  • 343
  • 1
  • 4
  • 15
0
votes
2 answers

how to test muti promise in one function with sinon

Here is my function, in this function, there are two promise function in the 'start' function. How should I test the 'start' function. export class TTT{ fun1(){ return new Promise(((resolve, reject) => { console.log('function1'); …
lily
  • 23
  • 4
0
votes
1 answer

Sinon stub returns empty response when mocking multiple methods of same object

I am trying to mock two methods in a object using sinon. One of it returns the expected response but the other method returns an empty json. describe("Unit test cases ", () => { describe("scenario 1", function() { let getResponse,…
Priya
  • 59
  • 7
0
votes
1 answer

Sinon Spy not called but original function is called

My spy is not being called, even though I can see the console log in the original function getting called Mocha test: const { expect } = require('chai'); const supertest = require('supertest'); const MyController =…
user123
  • 99
  • 1
  • 11
0
votes
2 answers

Sinon.spy fails with imported method

I have of couple JS modules, let's say A and B. In module A, I have a method which depends on another method imported from module B. Now how do I test with sinon.spy, whether the method from A triggers the method from B? //ModuleA.js import{…
Murali Nepalli
  • 1,588
  • 8
  • 17
0
votes
1 answer

Express: I don't understand how to use sinon

I have a controller with method: registration(req, res) { if (!req.user) return res.status(401).send('Registration failed'); const { user } = req; return res.status(201).json({ user }); }, I want to test the registration method which sends…
Sergei R
  • 701
  • 4
  • 10
  • 24
0
votes
0 answers

Sinon callsFake returns same output in other files

I have my module file with below code whenever promise is rejected process.exit is called with code 1 module.exports = myPromiseReturningFunc(args) .then(el => { return true; }) .catch(err => { console.error('Error ', err) return…
kailash yogeshwar
  • 836
  • 1
  • 9
  • 26
0
votes
1 answer

Enzyme restore getEelemenById before each test

I stub getElementById in beforeEach, and want to restore it before another test and stub again with anothter returns value. Because now I recieve error TypeError: Attempted to wrap getElementById which is already wrapped let loginUrl = 'loginUrl' …
Palaniichuk Dmytro
  • 2,943
  • 12
  • 36
  • 66
0
votes
2 answers

Testing for server in Koa

I am using Koa for web development in NodeJS, I have a server file, which does nothing but to start the server and initialise few middlewares. Following is the sample code server.js const Koa = require('koa'); var Router = require('koa-router'); var…
chaitanya90
  • 697
  • 2
  • 8
  • 24
0
votes
0 answers

How to test code with jQuery promises in Mocha?

I have a code that needs to be tested with Mocha. In a certain part of the code, this is included: var deferred = $.Deferred(); And I am getting this error: TypeError: $.Deferred is not a function I tried to add jQuery to the Mocha tests, and…
JorgeDLuffy
  • 190
  • 1
  • 9
0
votes
1 answer

Cypress `onCall()` assertion support seems not documented?

In this cypress example I find onCall() method which seems to be 'Sinon', as I find it here. The supported assertions in Cypress are mentioned here and it includes sinon-chai, which does not mention onCall(). My question: what assertions are…
musicformellons
  • 12,283
  • 4
  • 51
  • 86
0
votes
1 answer

Webcomponent Tester - How to assert a function not to be called?

Using Polymer 1.* and webcomponent tester... I have spy(alert, 'open') and expect(alert.open).to.have.not.been.called;. How can I assert a function is not called? Right now this. If I inverse it with expect(alert.open).to.have.been.called;, it…
dman
  • 10,406
  • 18
  • 102
  • 201
0
votes
0 answers

How to restore all methods of a mock?

I am using sinon to create a mock but its methods are not getting restored after calling restore and when i again try to wrap them i get error. Here is what I am doing:- describe(‘test suite’ , () => { describe('test suite',()=>{ …
vidit mathur
  • 62
  • 1
  • 2
  • 8