sinon

How to Mock postgresql (pg) in node.js using jest

坚强是说给别人听的谎言 提交于 2020-05-27 09:27:47
问题 I am new in node.js. I am writing code in node.js for postgresql using pg and pg-native for serverless app. I need to write unit test for it. I am unable to mock pg client using jest or sinon. My actual code is like this const { Client } = require('pg'); export const getAlerts = async (event, context) => { const client = new Client({ user: process.env.DB_USER, host: process.env.DB_HOST, database: process.env.DB_DATABASE, password: process.env.DB_PASSWORD, port: process.env.PORT }); await

Sinon in typescript stub

回眸只為那壹抹淺笑 提交于 2020-05-17 08:52:47
问题 Sinon in typescript not able to import sub module propely ..please find below code The below code is file parent.ts import submodule from './sub-module' class Parent { /** * name */ public parentmethod() { let sub = new submodule(); let result = sub.submethod(); return result; } } export default Parent and submodule code named as submodule.ts class submodule{ public submethod(){ return "hai submodule" } } export default submodule and unit test script as below "use strict"; import chai from

Sinon in typescript stub

我们两清 提交于 2020-05-17 08:52:27
问题 Sinon in typescript not able to import sub module propely ..please find below code The below code is file parent.ts import submodule from './sub-module' class Parent { /** * name */ public parentmethod() { let sub = new submodule(); let result = sub.submethod(); return result; } } export default Parent and submodule code named as submodule.ts class submodule{ public submethod(){ return "hai submodule" } } export default submodule and unit test script as below "use strict"; import chai from

Stub a standalone module.exports function using rewire

拥有回忆 提交于 2020-03-23 12:19:04
问题 I am trying to stub a module.exports function. But I have some trouble. I will give you a sudo code of the situation. MyController.js const sendOTPOnPhone = rewire('../../src/services/OtpService/sendOTPOnPhone') module.exports = async function(req, res) { const { error, data } = await sendOTPOnPhone(req.query.phone) //this is I want to stub if(error) return return res.send(error) return res.send(data) } sendOTPService.js module.exports = async function(phone) { const result = await fetch(

How to check the property value after mocking a function : Assertion Error ,mocha

丶灬走出姿态 提交于 2020-03-05 02:13:03
问题 As per suggestion in question enter link description here I mock readFileSync and mocked my outer function now I want to verify if the variables value is set as expected or not file.js const fs1 = require('fs'); let param; module.export = { test, param } function test (outputParam) { param = fs1.readFileSync(outputParam); } I have stubbed this readFileSync and it returns specified file content as shown in the test below When I run the test I want to see the variable param has the file content

How to check the property value after mocking a function : Assertion Error ,mocha

落花浮王杯 提交于 2020-03-05 02:11:50
问题 As per suggestion in question enter link description here I mock readFileSync and mocked my outer function now I want to verify if the variables value is set as expected or not file.js const fs1 = require('fs'); let param; module.export = { test, param } function test (outputParam) { param = fs1.readFileSync(outputParam); } I have stubbed this readFileSync and it returns specified file content as shown in the test below When I run the test I want to see the variable param has the file content

How to check the property value after mocking a function : Assertion Error ,mocha

前提是你 提交于 2020-03-05 02:11:28
问题 As per suggestion in question enter link description here I mock readFileSync and mocked my outer function now I want to verify if the variables value is set as expected or not file.js const fs1 = require('fs'); let param; module.export = { test, param } function test (outputParam) { param = fs1.readFileSync(outputParam); } I have stubbed this readFileSync and it returns specified file content as shown in the test below When I run the test I want to see the variable param has the file content

sinon calledWith(new Error()) and with exact message

纵饮孤独 提交于 2020-01-24 04:28:13
问题 i need to test this function : //user.js function getUser(req,res,next){ helper.get_user(param1, param2, (err,file)=>{ if (err) return next(err);} my test function : it ("failed - helper.get_user throws error",sinon.test(function () { var req,res; var get_user = this.stub(helper,"get_user") get_user.yields(new Error("message")); var next = sinon.spy(next); user.get_user(req,res,next); expect(next).to.have.been.calledWith(new Error("other message")); })) for my assertion I'm using sinon-chai

Emberjs Testing a Component's action delegate

强颜欢笑 提交于 2020-01-24 01:07:21
问题 I'm trying to test a simple component that uses action delegation. I want to test that a certain action is sent to the actionDelegate of a component. I was thinking of using Sinon to check that the action was being sent, but I can't work out how to replicate the structure that Ember uses to send its actions to its delegates/targets. What structure would my sinon "spy delegate" object take in order for me to check that the component is delegating the event using "send" when the user clicks on

Stubbing a class method with Sinon.js

泄露秘密 提交于 2020-01-18 08:35:23
问题 I am trying to stub a method using sinon.js but I get the following error: Uncaught TypeError: Attempted to wrap undefined property sample_pressure as function I also went to this question (Stubbing and/or mocking a class in sinon.js?) and copied and pasted the code but I get the same error. Here is my code: Sensor = (function() { // A simple Sensor class // Constructor function Sensor(pressure) { this.pressure = pressure; } Sensor.prototype.sample_pressure = function() { return this.pressure