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
2
votes
1 answer

How to match some values of object using sinon stub

I've been writing test using sinon. During the same I wrote stub where some input parameters are passed and an object is returned. This object returns some values and a random date value generated by system at the time of execution. So need guidance…
Aamer Rasheed
  • 115
  • 3
  • 14
2
votes
0 answers

How to properly write unit tests for router modules in NodeJS

I'm new to nodeJS and testing and I'd like to know how I can test my application routes properly. I've read some articles that uses supertest and chai-http to call the POST method but I believe this way would be more of an integration testing…
jrmtmys
  • 33
  • 4
2
votes
2 answers

Unable to mock node-fetch using fetch-mock

I am trying to do unit testing for a simple function which sends a get request, receives a response and then returns a promise object with the success or the failure message. Following is the function: module.exports.hello = async (event, context)…
2
votes
2 answers

Getting Invalid Chai property: 'calledWith'

I'm working on setting up unit tests for my express app. When I run my test it fails with this error `` import * as timestamp from './timestamp' import chai, { expect } from 'chai' import sinonChai from 'sinon-chai' import { mockReq, mockRes } from…
Justin Young
  • 2,393
  • 3
  • 36
  • 62
2
votes
1 answer

Cannot mock passport authenticate('local') method with sinon

I'm trying to mock the passport.authenticate('local'): app.post('/login', passport.authenticate('local'), (req, res, next) => {console.log('should enter');}) Am using Sinon, but the method doesn't execute the console.log inside the login…
EugenSunic
  • 13,162
  • 13
  • 64
  • 86
2
votes
1 answer

How do I check if element exists with Mocha Chai Sinon?

I would like to know how can I check if an element on the UI exists by id or class. I'm using teaspoon-mocha, Sinon, and chai. I tried next but it doesn't work: expect($('my-id')).to.be.true;
Jakub
  • 2,367
  • 6
  • 31
  • 82
2
votes
1 answer

How to stub dynamical import with Sinon JS

I try to stub with sinon js the import, how actyally to do that, import XLSX from 'xlsx' beforeEach(() => sinon.stub(sheetJS).resolve({})) - does not work for me, and I cath error that resolve is not a function export default (data, sheetName,…
Palaniichuk Dmytro
  • 2,943
  • 12
  • 36
  • 66
2
votes
1 answer

Vue.js unit tests how to fake an audioContext with Sinon stub?

I am trying to test an audio plugin , but I don't see how to write the correct expectation for : audioContex.resume() audioContext.suspend() The test executes correctly , updating the directive ( Vue.noise) and executing the command…
user762579
2
votes
0 answers

How to mock FileList in $("fileupload").files[0]?

1I am not able to make a mock for file upload using J query. $('#fileUpload')[0].files[0]= "mock image data here" $ ('#fileUpload').trigger ('change'); Please ref attachment .[Actual FileList object]
Anurag G
  • 272
  • 4
  • 16
2
votes
1 answer

How to test properly the usage of $injector?

I have one service which has the below function injectService(serviceToInject: string, methodToInvoke: string){ let service = this.$injector.get(serviceToInject); service[methodToInvoke](); } I was wondering how I could test this ? I tried…
geo
  • 2,283
  • 5
  • 28
  • 46
2
votes
0 answers

Sinon-chai expect String to contain substrings in specified order

Is there a way in sinon-chai to test whether a string contains sub-strings in the specified order? Something like: expect("Hello World, it's a lovely day!").to.contain.in.order("World", "day") Similar to what the sinon-chai-in-order does for spy…
MartinTeeVarga
  • 10,478
  • 12
  • 61
  • 98
2
votes
1 answer

How to mock promisified Mysql data using sinon for Unit Testing

Is it possible to mock promisified queries in NodeJS using sinon for require('promise-mysql') npm package. As Sinon allows us to mock and / or stub out methods on objects. Say I want to override the createConnection() method so that it returns a…
Shri.harry
  • 287
  • 1
  • 2
  • 15
2
votes
1 answer

Simulate a click on span tag in enzyme

I have a span tag in my component and I need to click it using enzyme Reserve this chat Here is my…
Thomas John
  • 2,138
  • 2
  • 22
  • 38
2
votes
2 answers

Expect method to have been called is not fulfilled on "onInput" for a contentEditable element

I have a component that uses contentEditable as an input method. The part from the component that is of interest is:
Raul Rene
  • 10,014
  • 9
  • 53
  • 75
2
votes
1 answer

How to expose a module (sinon, chai) as global variables with correct types?

In Js tests, mocha, chai and sinon are commonly exposed as global variables to save some import, usually via karma plugins. Installing mocha typings goes well, mocha describe, it... are correctly exposed as global variables with correct…
Offirmo
  • 18,962
  • 12
  • 76
  • 97