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

How can one prove the invocation of fulfillment callback using mocha, chai and sinon?

Consider the following mocha+chai+sinon test: it("will invoke the 'then' callback if the executor calls its first argument", function(done){ let executor = function(resolve, reject){ resolve(); } let p = new Promise(executor); …
user3887150
0
votes
0 answers

Stubbing a nested function using Sinon.js

I have a nested object -> let somevar = { read : () => { return { fetchsomething : () => { somemodule.methodName(params, cb (err,data) { if(err){ //reject promise …
user4387602
  • 103
  • 1
  • 1
  • 7
0
votes
1 answer

Mocking/stubbing whether or debug log is enabled?

How do I write a mock test that allows me to validate that an inaccessible property (debugLog) is set to true? Do I try to find a way to find the value of the property? Do I verify that console.debug is set? Does a spy make sense in this situation…
phil o.O
  • 406
  • 2
  • 4
  • 20
0
votes
0 answers

Jasmine - Spy on a function call within a function

Being pretty new to testing, I am making some silly assumptions and hence my test cases are not running. My interceptor factory looks something like: angular.module('svcs') .factory('authorizationInterceptor', function ($q) { var…
StrugglingCoder
  • 4,781
  • 16
  • 69
  • 103
0
votes
1 answer

Sinon, Chai test case with multiple nested functions

I tried to load multiple external js using javascript. I had separate code for injection logic. When I load one js file means the test case working fine. But when I try to load multiple js file the test case FAILED. Main.js var externalJs =…
RSKMR
  • 1,812
  • 5
  • 32
  • 73
0
votes
1 answer

How to compare json object with sinonChai?

Background I am creating my test suite and I am using sinon for stubs and chai as an assertion framework. To combine the two, I am using sinon-chai. Objective I want to make sure that my stub is being called with the correct parameters. To do that I…
Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
0
votes
2 answers

How can we stub and respond to a particular function call in sinon js

Suppose we have a function test, that has been called multiple times with different values. How can we stub it for a particular parameter value. Like in the following function test(key, cb) { // code cb(); } test('one',…
Rakesh Rawat
  • 327
  • 3
  • 14
0
votes
2 answers

Chai + Sinon error: method is already wrapped

I am getting error: TypeError: Attempted to wrap ajax which is already wrapped Error: Stack Trace for original chai.should(); describe("Test API", function() { it('executes a GET request for ISPs', function() { var mySpy = sinon.spy(jQuery,…
0
votes
1 answer

Unit testing bluebird promise bind function

I have the following function that uses bind to bind a context to the then chains. When i try and test it, it throws TypeError: redisClient.hgetallAsync(...).bind is not a function myFunc() { let self = this; return…
cusejuice
  • 10,285
  • 26
  • 90
  • 145
0
votes
2 answers

Test callback invocation at the end of promise chain

I am dealing with a code mixing node-style callbacks and Bluebird promises, and I need to write some unit tests for it. In particular, cache.js exposes the init() function, which works with promises. It is then called by the doSomething() function…
rippeltippel
  • 369
  • 1
  • 7
  • 15
0
votes
1 answer

Testing function chains using Sinon.JS

How can I test a function like the following using Sinon.JS? export function getToken(done) { const kc = Keycloak(config) kc.init({ onLoad: 'login-required' }) .success(authenticated => { authenticated ? done(null, kc.token) : done(new…
Hawkes
  • 457
  • 1
  • 4
  • 16
0
votes
1 answer

Sinon Stub in Mocha Not Working

I'm struggling with a pretty trivial problem. I am able to stub functions in all dependency packages and it's working great but when I try and stub my own functions I can't seem to get it working. See the following simple example: test.js: var…
Gregg
  • 1,477
  • 1
  • 16
  • 17
0
votes
1 answer

How am I able to test that a Backbone model's method bound to the event bus has fired when using Karma and Sinon?

When testing that a backbone model's event has fired with a sinon spy, it erroneously errors: expected doSomething to be called once but was called 0 times, even though it seems to execute when a console log is put in the method's body. The testing…
Afs35mm
  • 549
  • 2
  • 8
  • 21
0
votes
0 answers

sinon stub on global function

I try to stub any global function: function randomNumber(min, max){/*...*/} (window.randomNumber === randomNumber) but when I create stub in test case sinon.stub(window, 'randomNumber') and mocks result randomNumber.returns(1);) it doesn't work and…
Alcadur
  • 681
  • 1
  • 8
  • 22
0
votes
1 answer

How to stub an object using Sinon?

I'm wondering if/how i can use Sinon to stub the object mappedValues nested in the function below: function getValueFromObj(key) { var mappedValues = { "a": "aaa", "b": "bbb", "c": "ccc", "d": "ddd", }; …
Billy Blob Snortin
  • 1,101
  • 3
  • 11
  • 17