Mock requires (ed) service

I'm trying to mock a service used by my function using sinon, but I can't find a way to inject the mock into my function. The service is acquired using require My function is like this: // something.js const service = require('./service'); module.exp

redis redis publish method using otherwise?

How can I stub the redis publish method? // module ipc const redis = require('redis'); module.exports = class IPC { constructor() { = redis.createClient(); } publish(data) {'hello', JSON.stringify(data)); } } and another mo

Mocha / Otherwise mongoose test inside express

I try to test this express route with mocha, supertest and sinon. Test can't pass promise, it stop after the first mongoose call in User.find callback function with a pending error message : Error: timeout of 2000ms exceeded. Ensure the done() callba

How to test unitStorage using otherwise

I am trying to test localStorage using sinon. Basically I am very new to unit testing so this might be very basic. Update I managed to come up with this but now its giving me a new error Should wrap property of object Test describe('Initial State', (

Test and replace parameters in the POST request

Guys how can I stub params in POST request, for example here a part of function gridCalculator : function(req,res){ // calculation logic var options=[]; options.dateFirstLicensed = req.param('DateFirstLicensed'); options.dateFirstInsured = req.param(

Asserting function calls within a promise

I'm writing some tests for an async node.js function which returns a promise using the Mocha, Chai and Sinon libraries. Let's say this is my function: function foo(params) { return ( mkdir(params) .then(dir => writeFile(dir)) ) } mkdir & writeFile

crush an entire class to test in otherwise

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 the wrong thing... Suppose I'm developing a WidgetManager class that will operate on Widget objects. How do

How to test asynchronous functions redux-thunk middleware?

I'm trying to test my asyn thunk middleware function using mocha, chai and sinon (my first time!). Please consider my files: ayncActionCreators.js export const fetchCurrentUser = () => { return (dispatch) => { setTimeout(dispatch, 100); } }; ayncAct

Can not test the submission manager in the 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 JSDOM and have looked around a lot online to find anyone with a similar issue. Ther

Mocking / stubbing Method of saving the Mongoose model

Given a simple Mongoose model: import mongoose, { Schema } from 'mongoose'; const PostSchema = Schema({ title: { type: String }, postDate: { type: Date, default: } }, { timestamps: true }); const Post = mongoose.model('Post', PostSchema); ex

Otherwise.Stub in Node with AWS-SDK

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 request = require('superagent'), expect = require('cha

Unable to test debunked Backbone view event

When I am not throttling/debouncing the function the test passes. However when I debounce the event to prevent flooding the server the test no longer passes. Mocha outputs AssertionError: expected execute to have been called at least once, but it was

Prompt Reminder Test in NodeJS with Mocha & amp; If not

I am trying to test a method call that is returning a promise however I am having trouble. This in NodeJS code and I am using Mocha, Chai, and Sinon to run the tests. The test I currently have is: it('should execute promise\'s success callback', func

How should I avoid bucking properties with Sinon.js

I've discovered that Sinon doesn't let you stub properties, only methods. I'm trying to figure out how to deal with/embrace this. I have the following code: var Player = { addPoints: function(points) { this.score += points; }, score: 0 } var Game = {

Javascript: Mock Builder Using Elsewhere

I am pulling my hair out trying to figure out how to mock a constructor using sinon. I have a function that will create multiple widgets by calling a constructor that accepts a few arguments. I want to verify that the constructor is called the correc

Clean stubs easily

Is there a way to easily reset all sinon spys mocks and stubs that will work cleanly with mocha's beforeEach blocks. I see sandboxing is an option but I do not see how you can use a sandbox for this beforeEach -> sinon.stub some, 'method' sinon.stub

fool xmlhttprequests with casperjs

I'm writing end-to-end tests with casperjs and would like to fake ajax server responses I've came up with the idea of including a simple script that mocks the xmlhttprequest object and would always return my expected results, like the following var a

How can I test the jquery dialog?

I wrote below code, try to test if a jquery dialog get excused and displayed. var jqueryMock = sinon.mock(jQuery); var dialogExpectation = jqueryMock.expects("dialog"); dialogExpectation.once(); //call my function, in which create a jquery dialo