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

How can I Mock node-rest-client request?

I'm using node-rest-client for my project and I've come to the point where I want to start unit testing my classes that utilize node-rest-client. Is there any examples on how I can mock the Client in my tests? I am using Sinon in my unit testing.
Praveen
  • 447
  • 5
  • 9
0
votes
2 answers

Javascript sinon testing callback

I'm trying to test that certain function is called in a callback, however I don't understand how to wrap the outer function. I'm using mocha as my testing suite, with chai as my assertion library, and sinon for my fakes. fileToTest.js const…
Ragnyll
  • 3
  • 1
  • 6
0
votes
1 answer

Sinon spy: Attempted to wrap undefined property 'path' as function

The following spy on location.path is failing with an error: Attempted to wrap undefined property path as function it('should redirect location.path', function() { sinon.spy(location, 'path'); scope.create(); …
0
votes
1 answer

How to check the number of arguments that a function has been called with Mocha, Chai and Sinon?

Lets say we have a service Foo which is exporting a function function bar(x,y){ console.log(x,y); } And we want to write a unit test which will test that this function is called with 2 arguments. I have tried this var args =…
geo
  • 2,283
  • 5
  • 28
  • 46
0
votes
1 answer

useFakeTimers mocha chai sinon - not the right result on a test

I am trying to run a test where I want to verify that my helper file is running correctly, and if I have an expired token, I get an error kickback and cannot proceed. I have a feeling that I can only fake the time directly in the test, and not…
0
votes
0 answers

How to check wether $interval is called with exact arguments or not in sinon.js

I want to test whether the callback function of $interval is getting called or not after a certain time interval. But I am getting the argument list as empty. I don't know why. Below is the code which contains $interval - (function() { "use…
Neha Gupta
  • 987
  • 5
  • 16
  • 35
0
votes
1 answer

Sinon: Test the order of function call and var change

When we have // arrange var testVar = 0; var testFunction = sandbox.stub(); // act TestClass.TestMethod(); // it changes testVar and calls testFunction Is there a way to test if testVar is changed before testFunction is called? Edit: looks like…
Vergil Penkov
  • 380
  • 2
  • 11
0
votes
0 answers

Tests with Sinon + Chai fail after refactor to implement promises

I got a lot of callbacks in this application that ended up as a good example of a 'callback-hell'. Methods with 200 or 300 lines and 10, 15 nested callbacks each. Then, as a good practice, I detached most of these callbacks, named then and created…
Victor Ferreira
  • 6,151
  • 13
  • 64
  • 120
0
votes
1 answer

Stub isAuthenticated written with composable-middleware

I have this middleware function, written with composable-middleware package. var compose = require('composable-middleware'); module.exports.isAuthenticated = function () { return compose() .use(function (req, res, next) { var…
GarryOne
  • 1,430
  • 17
  • 21
0
votes
1 answer

How to get a sinon stub to call another function on nth call

I want to use a sinon stub to asynchronously test an event emitter. I want the stub to call a callback after it is called. I thought stub.yields was what I want but not. Is there a neat way to do this? it('asynchronously emits finish after…
Cool Blue
  • 6,438
  • 6
  • 29
  • 68
0
votes
2 answers

"this" reference is not working in nodeJs

I have two methods in my nodeJs code like function method1(id,callback){ var data = method2(); callback(null,data); } function method2(){ return xxx; } module.exports.method1 = method1; module.exports.method2 = method2; for testing…
mukul
  • 433
  • 7
  • 18
0
votes
2 answers

Chrome extension unit test throws 'unsafe-eval' with Sinon

I am unit testing my chrome extension with mocha, chai, and sinon. When I try to stub an object from method I get: EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following…
0
votes
1 answer

Mohca testing failure

I need to test storeDocument function when debug = false which will call createStorageDocument. But for my following test code is giving an error 'TypeError: Attempted to wrap undefined property createStorageDocument as function' What am I doing…
Shaolin
  • 2,541
  • 4
  • 30
  • 41
0
votes
1 answer

Unit testing MOCHA SINON CHAI (check call nested functions)

If anyone understands the tests, please tell me how I can implement test for two things: 1) Was obj.newRing method called, when makeRing function starts. 2) whether the parameter 'num' is passed to the function makeRing(num) is Matches with the…
0
votes
0 answers

Dropdown Component Unit Test Case using in sinon+chai : ng-forward

I want to write the unit test case for this component Dropdown Component But I am unable to write the test case in sinon+chai using ng-forward. Can somebody guide me in this.
Ashutosh Singh
  • 806
  • 1
  • 8
  • 20
1 2 3
17
18