sinon

Stubbing a Mongoose model with Sinon

六月ゝ 毕业季﹏ 提交于 2019-11-26 14:27:45
问题 I want to create a stub for the Mongoose save method in a particular model, so that any instance of my model I create will call the stub instead of the normal Mongoose save method. My understanding is that the only way to do this is to stub the entire model like this: var stub = sinon.stub(myModel.prototype); Unfortunately, this line of code causes my tests to throw the following error: TypeError: Cannot read property 'states' of undefined Does anyone know what is going wrong here? 回答1: There

How to test an ES6 class that needs jquery?

落花浮王杯 提交于 2019-11-26 11:39:19
问题 I have an ES6 module that needs jquery. import $ from \'jquery\'; export class Weather { /** * Constructor for Weather class * * @param latitude * @param longitude */ constructor(latitude, longitude) { this.latitude = latitude; this.longitude = longitude; } /** * Fetches the weather using API */ getWeather() { return $.ajax({ url: \'http://localhost:8080/weather?lat=\' + this.latitude + \'&lon=\' + this.longitude, method: \"GET\", }).promise(); } } Module works fine when use it in my main

How to Unit Test React-Redux Connected Components?

本秂侑毒 提交于 2019-11-26 08:09:21
问题 I am using Mocha, Chai, Karma, Sinon, Webpack for Unit tests. I followed this link to configure my testing environment for React-Redux Code. How to implement testing + code coverage on React with Karma, Babel, and Webpack I can successfully test my action and reducers javascript code, but when it comes to testing my components it always throw some error. import React from \'react\'; import TestUtils from \'react/lib/ReactTestUtils\'; //I like using the Test Utils, but you can just use the DOM