Sinon Questions
Ad
How to stub isFile from fs.statSync
I am writing a unit test for file and path manipulations, but i cannot stub isfile in fs.statsync(filepath).isfile() .
How can I test that a promise have been waited for (and not just created) using Sinon?
Let's say i have a function: const someaction = async(): promise<string> => { /* do stuff */ }; and
Unit test for Event Emitter Nodejs?
I created a simple class for polling by event emitter of nodejs for example:
Console logging sinon.spy() shows [Function] instead of the contents of the spy
I am trying to see the output of sinon.spy() but when i do a console.log( res.render ) i just see
Assert that the function passed into a stubbed function is the correct function
I'm trying to test my node module using mocha. the module is very small here is an example... import { sharedfunctiona,
How to mock npm module with sinon/mocha
I'm trying to test a function that calls the module cors. i want to test that cors would be called. for that, i'd have
Mocking 'os' nodejs module issues
I'm currently facing some difficulties mocking the 'os' module in nodejs. i'd like to mock the 'networkinterfaces' function of the module to
NodeJS: How to assert if event callback function was called using sinon
How can i test if a callback function from a event listener is called? for example, i have the following code where app.js initializes the
Stub not getting called inside .then()
I am working on unit testing an express application. i am trying to mock up my external dependencies (express, database, etc) and am close to a
How to manipulate results of Mocha test in Node.js?
I have a simple mocha file: const assert = require('assert'); describe('array', function () { describe('#indexof()', function
Ad
How to mock events with sinon?
Here is my simple program where i'm trying to get user's data via ldapclient. i need to test it without internet connection so wondering how to
Unable to Mock Node fs Modules with Sinon
I am unable to properly mock the promises methods of the node fs module. my appdata.ts file calls the real
sinon not detecting private function called inside promise
I am quit new to sinon and rewire. i am trying to check if private function was called with in promise. private function stubbed is getting
Using Sinon SinonStubbedInstance with Typescript
I'm using sinon to stub an instance of express-request. it looks something like this: let req =
Sinon and Mocha: How to await for a promised to be resolved before assertion in test function?
I have a file where, function fetchdevices () { device.findall() .then(alldevices =>
How to address nested functions using Sinon?
Using sequelize in the code, i can't stub crucial inner functions of it, such as .save(), .scope(), etc.. nesting doesn't seem to work. as
Stub function does not executed when executing test using sinon and mocha
I'm trying to mock a function in order to pass tests using sinon and mocha. app.js: const
how to test that a method rethrow existing error using chai and sinon
We have a method which takes as arguments a potential error triggered a level higher. we want to test handlefailure((msg, err)
Auth middleware not calling stub - NodeJS, sinon
Similar questions have been asked before & i have looked at & followed them but no luck:
Sinon - returns is not a function
I'm writing unit tests and i have a module file like so: #!/usr/bin/env node const shelljs = require('shelljs'); const
How to mock, and test, closures with mocha, chai and sinon
I have a simple node.js middleware that i would like to test is it being processed correctly. simple middleware
Ad
Javascript mock third-party node library on function call
I'm using sinon and i want to do something very simple, and i cannot find any solution after a lot of searching. i have class
console.log unit test failing under mocha with unknown error
My unit test failing for following code.when i run test i see below result with unknown error.i am not getting how to test second parameter paylod
How can I spy on an imported function in a grandparent class when testing a child class?
I'm having trouble spying on a function that is imported from a node module. i am testing a child class and the module is imported in a
Attempted to wrap undefined property findOneAndUpdate as function
I wrote a unit test for my put /cars/:id using sinon.js: unittest.js: const sinon = require('sinon');
Stubbing Out Middleware
I'm trying to use sinon to stub out some custom middleware in an express route but it's not working as i expect it to. i expect it to not log "i
Stubbing auth0 in firebase functions
I have the following firebase function that makes use of auth0 to get a user profile. 'use strict'; const { dialogflow,
Stub function with return function with sinon?
I want to make unit testing and cover my code, this is my code, how can cover the createclient with sinon ? const client =
How to stub mongoose methods with multiple arguments in Sinon?
I am using mongoose in node.js and here is my dao method. function findpostsbycategoryid(categoryid, first, second) { var
Sinon stubbing giving 'is not a function' error
First time really using sinon and i am having some issues with the mocking library. all i am trying to do is stub/mock out a function from
Testing with Sinon-Chai that an individual callback in a Node JS Express route with multiple callbacks is called
I'm relatively new to node and sinon. this application was made with express, and i'm using mocha, chai, and sinon. using sinon-chai, i'm post
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) =>
Ad
How to mock return value of async function?
I'm trying to test function which uses 'easy-soap-request' library. i want to mock results returned by 'soaprequest' function. i've tried
How can i unit test the dependency method
It's my code written in typescript; i want to test the private getfunc method and the method of redisclient have been
How to mock/pass a Nodejs helper utility which executes functions in it using mocha-chai-sinon
Let's say i have a file like below: src/blah.js var foo = require("../../something/foo.js"); var goo = new foo({ host:
Node.js - Mock result of a promise
I want to mock the result of a function within a node module so that i can run assertions. considering the following node module:
Sinon - How to make a function thats called indirectly return something
I have been struggling on how i can mock a function so that i can return a fake value from that function. i have a simple script that can
How to mock d3.select.selectall with sinon?
I have the following code that i need to test: window.d3.select(id).selectall("text").attr("font-family", "fontawesome"); var
Best practices for using sinon for nodeJS unit testing
I'm coming from java experience with spring framework and looking for the most elegant way to write tests with mocks in nodejs. for java
Sinon stub being skipped as node express middleware
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
Sinon stub on prototype, check value of actual instance it is called on
I have a sinon stub on a prototype and method... stub = sinon.stub(mytype.prototype, 'somefunction');
sinon spy doesn't register call in a generator loop?
I want to check that a piece of code is being called, so i'm using a sinon spy to assert this. however, the spy seems to be failing, despite
How to stub a module function that is called from another function
My module.ts file has 2 functions: export async function foo() { var barval = await bar();
Ad
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.
How to unit test an API that depends on an external library "<script src="http://stripe[...]"
I am trying to unit test an api call to ensure that it has been called with the correct properties. this api call depends on stripe's external
With Sinon, how can I mocked http.foo.get when http is a property?
I have a file i wish to test, with an http-client that should be mocked: schema.js: const { http
stub doesn't return the resolve data in proxyquire getting undefined
I am not able get the resolved value in the response the promise stub returns undefined otphelper.sendotp =
Mocha + Sinon testing mongoose methods being called
I have following function called on specific route and i am trying to test if the mongoose method inside is called with specific parameter. my
Sinon - How to check that array keys all have particular value?
I should preface everything by saying that i have never written a unit test before, so if you can be explicit for me and not presume
Why can't I properly stub the twilio library with sinon?
In my code, i have: function handlemessage() { const twilio = require('twilio')(process.env.twilio_account_sid,
Sinon stub function used with destructuring
I wish to stub a function used in the file i'm currently testing. this function is required with a destructuring like this: const
Spy on imported function
I want to spy on a function that is executed as soon as the file is required. in the example below i want to spy on bar. i have the following
Test node-schedule with sinon FakeTimers
I want to test my schedulejob from the node-schedule package. with sinon usefaketimers() i can skip the
Stubbing express middleware functions with sinon is
Description i try to set stub fakes for a express middleware function and it's not replacing over. what i'm trying (how to
Ad
Can't decide how to test this code
I am attempting to write a test for the following code using mocha, chai, chai as promised & sinon but i am not too familiar with testing and
Testing a component which calls an async function
I have a react component which calls an async function passed in as a prop and then calls another function in the
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.
Testing that promise resolved not until timeout sinon chai
We have a simple wait method leveraging promises in our node app exports.wait = (timeout) => { return new promise((resolve)
how to test a Module in NodeJs without function in it?
I have read and tried many ways to do this,i have a module like below . //echo.js module.exports = (services, request) => {
How to stub a method that is indirectly called inside another method
I've a node / express rest api. to test my userscontroller.login method, that will indirectly call dbconnector.readdoc() function, i need to stub
How to test for an event to have been fired and its value?
I couldn't find any working examples to test for whether an event was emitted and whether the emitted value is as expected. here is the
JavaScript / Mocha - How to test if function call was awaited
I would like to write a test that check if my function calls other functions using the await keyword. i'd like my test to
Javascript Test - Verify if Authorization header is correct using axios
I'm using an axios interceptor to set the authorization token in requests headers. axios.interceptors.request.use(config => {
Unit test issue with Mocha and Sinon using javascript
I am trying to use mocha and sinon to test a piece of code that is using an aws service. below the code: exports.init = ({
Testing a function entirely using stubs
I have been writing tests for the past couple of weeks now. at my place of work we are using mocha as our test runner and chai as an assertion
Ad
Sinon: How to return based on actual arguments being sent?
Let's say we have a function with two arguments. it's being called many times with different arguments on every call. so, its impossible to stub
how to to make sinon return non promise I do mock expect
I am using sinon to mock a return for a function and here is my code:
stub fetch unit test react with enzyme and jest
I am trying to stub an api call in react using enzyme and jest. my react component code looks like the following. this works
Sinon doesn't stub my intern fuctions while testing. (ExpressJS)
Currently i want to implement sinon stub's for my express routes. the problem is, that i don't understand why it isnt replacing my functions.
Cannot Stub Function Returning Promise
I was trying to stub an arrow function removeuserentry, but when executing acctrmrouter in the test, my stub seems being
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:
Understanding Sinon Spies: What happens when a spy-wrapped method is called?
When i wrap the method of a class into a sinon-spy like this: sinon.spy(myobject, "mymethod") what happens
Understanding Sinon clock `tick` vs `tickAasync`
I am trying to understand the difference between clock.tick and clock.tickasync and where should i use each one. the
Unit-test of redux-saga throws error: runSaga must be called on an iterator
I'm very green when it comes to coding with react and redux, and testing it with jest, enzyme and sinon, so bear with me. i'm trying to
nodejs mocha - not able to test promises with stubs
I am trying to unit test promises with mocha, however, i am having two issues while testing promises. 1) i am having error: timeout
Mocha / Sinon Unit test JS Class and Instance issue
I'm trying to unit test some express middleware which has dependencies on some classes i've made. middleware.js const
Ad
Writing unit tests for method that uses jwt token in javascript
I have been trying to write unit test in javascript for the method which uses jwt token validation. so the results are fetched only if the token
How to stub document method with sinon - React
Import react, { proptypes, component } from 'react'; import classnames from 'classnames/bind'; import { get, includes } from 'lodash';
Why doesn't sinon recognize my stub?
Let's say i have a module that exports like this: module.exports = mymodule; then in my test file, i require the
Why doesn't my sinon fake server return anything?
I'm trying to setup a fake sinon server for testing some requests. in the code below, my callback function never gets called. the test errors out
Sinon anonymous stub passed as a parameter
I am trying to test a function in a redux container but the issue is barely about redux or react. basically the fetchdata function i am trying to
React.js unit test click event with Enzyme and Sinon
I'm trying to attach a spy to a click event on my react component. i am using enzyme with mocha and chai but i'm having
stubbing an entire class for testing in sinon
Preamble: i've read lots of of so and blog posts, but haven't seen anything that answers this particular question. maybe i'm just looking for
Creating a stub of document.getSelection using Sinon
My function, which you can find below, uses document.getselectionto get the currently selected text on the screen. i need to be able
How to Unit Test React-Redux Connected Components?
I am using mocha, chai, karma, sinon, webpack for unit tests. i followed this link to configure my testing environment for react-redux
How to spy on a method that receives function arguments?
If i have a function: function x() { some.external.library.method('x'); } then i can test it (i'm using mocha + sinon) where i spy on
How to unit test forms with Sinon and Chai
I am using chai, sinon, and mocha to test. i am using redux-forms, along with reactjs. i want to test what happens after i click submit on a forgot
Ad
Can't test submit handler in React component
I'm trying to test events for my component and i the submit handler isn't being called. all my unit tests are working except for the events. i'm using tape, sinon and
Ad
Blog Categories
Ad