sinon Questions

3

I am trying to stub the following: on('complete', function(data){ }); I only want to call the callback if the first parameter is 'complete'. The function I am testing also contains: on('error'...
Warrigal asked 14/5, 2012 at 17:23

3

I have a non object function on getConfig.js export default function () { /** do something **/ return { appConfig: { status: true } } } and under my main file import ...
Boustrophedon asked 6/11, 2019 at 4:24

5

Solved

How can I test sequence of function calls by Sinon.js? For example i have three (3) handlers in object, and want define sequence of handler calls. Is there any possibilities for this?
Neutrality asked 31/3, 2013 at 15:14

3

Solved

I've got a single method in my namespace that I'd like to mock, but I'd prefer that all the others work normally. Is it possible to have sinon mock a specific method while leaving the others the sa...
Brodie asked 24/7, 2014 at 2:14

3

Solved

I'd like to be able to stub my middleware functions on a per-test basis. The problem, as articulated here, is that I can't just stub my middleware functions since node has cached the middleware fun...
Sheply asked 13/11, 2019 at 7:10

1

There is a simple question I cannot find an answer to. When using: Node 17 + Typescript ESM ("type": "module" in package.json) Can I implement mock for one function only? or m...
Intimist asked 6/3, 2022 at 19:34

1

Solved

Let's say I am using auth0 in typescript in Node.js I have this class I want to test: ClassToTest.ts import { AuthenticationClient, AuthenticationClientOptions } from 'auth0'; export class ClassTo...
Jasik asked 21/6, 2023 at 1:10

6

Solved

In Sinon I can do the following: var myObj = { prop: 'foo' }; sinon.stub(myObj, 'prop').get(function getterFn() { return 'bar'; }); myObj.prop; // 'bar' But how can I do the same with Jest? ...
Cia asked 29/4, 2017 at 15:31

2

Solved

I'd like to unit test the following ES6 class: // service.js const InternalService = require('internal-service'); class Service { constructor(args) { this.internalService = new InternalService(...
Waxen asked 13/9, 2015 at 13:24

4

I have the following stack Node/Express backend Postgresql 10 database Mocha for testing Sinon for mocking I have written a bunch of end-to-end tests to test all my webservices. The problem is ...
Recommend asked 13/1, 2018 at 20:18

4

I'm trying to write out a unit test that stubs the getSignedUrl function from the @aws-sdk/s3-request-presigner package, however when I try stub out the function with sinon, I receive the error: ...
Bashemath asked 14/6, 2022 at 12:13

2

I have been struggling a lot to mock database in one of my side projects while writing junits. Can somebody please help me out here. Below is what the scenario looks like: Before that, the source ...
Wen asked 22/2, 2017 at 17:46

3

Solved

I'm using AVA + sinon to build my unit test. Since I need ES6 modules and I don't like babel, I'm using mjs files all over my project, including the test files. I use "--experimental-modules" argum...
Mark asked 8/6, 2018 at 14:54

3

Solved

I'm trying to test the behavior of a particular route. It continues to run the middleware even when I create a stub. I want the event authentication to simply pass for now. I understand that it's n...
Chifforobe asked 19/12, 2018 at 14:3

18

Are there any libraries out there to mock localStorage? I've been using Sinon.JS for most of my other javascript mocking and have found it is really great. My initial testing shows that localStor...
Duplex asked 14/7, 2012 at 16:24

3

I am a beginner of SinonJs, When I try to write some demo code, it cannot work, I don't know why. app.js const db = require('./db'); module.exports.signUpUser = (user) => { db.saveUser(user...
Tramontane asked 16/2, 2019 at 4:4

6

Solved

I get how to stub Mongoose models (thanks to Stubbing a Mongoose model with Sinon), but I don't quite understand how to stub calls like: myModel.findOne({"id": someId}) .where("someBooleanPropert...
Godhood asked 8/1, 2015 at 18:47

1

I want to create a test with Cypress that has a React component that uses an auth library (@okta/okta-react) with a HOC (withOktaAuth). My component looks like this: // Welcome.js import { withO...
Auricula asked 21/5, 2020 at 21:52

9

I am trying to write some test coverage for an app that uses the aws-sdk NPM module that pushes things up to a SQS queue, but I am unsure how to mock things correctly. Here is my test so far: var...
Andress asked 7/10, 2014 at 19:25

3

Solved

I'm trying to intercept a call with Sinon.js so I can do some logging and then execute the original call. I don't see a way to do this with sinon.spy(), but I think I can do it with sinon.stub(). ...
Millimeter asked 28/3, 2014 at 13:21

2

Solved

I know with sinon.js you can test that a spy was called a certain number of times: sinon.assert.calledTwice(mySpy.someMethod); And you can test that a spy was called with certain arguments: sin...
Kazim asked 29/8, 2018 at 4:28

2

Solved

I am mocking a function with Jest and the documentation says they are really 'spies'. I have also seen the use of spies in SinonJS but I could find no clear difference between the two. If they are ...
Curr asked 16/2, 2017 at 20:45

4

I've had no problems sorting out mocking the success condition, but cannot seem to fathom how to mock the failure/timeout conditions when using Sinon and Qunit to test and ajax function: My set up ...
Ukrainian asked 15/5, 2013 at 8:41

2

Solved

In javascript (ES6), I have a utility module which just contains some functions, and then in the end of the file, I export them like so: module.exports = { someFunction1, someFunction2, someFun...
Parham asked 5/10, 2016 at 7:42

1

Solved

I have the following code import { getIndexDocument } from "@assets"; class MetaController { public async exploreIndexDocument(): Promise<Asset | undefined> { const { result:...
Fasces asked 28/1, 2022 at 23:57

© 2022 - 2025 — McMap. All rights reserved.