sinon

sinon.replace vs sinon.stub just to replace return value?

家住魔仙堡 提交于 2020-12-23 11:01:08
问题 When using sinon I just want to replace my function's return value and don't need other infos like how many time it was called. Which one of them is better? sinon.replace(Component.prototype, 'getValue', () => 123); const myStub = sinon.stub(Component.prototype, 'getValue'); myStub.return(123); 回答1: I rarely see sinon.replace being used in many projects. The advantage of using stub is you can modify the return value many times for example. let getValueStub; before(function() { getValueStub =

sinon.replace vs sinon.stub just to replace return value?

耗尽温柔 提交于 2020-12-23 10:55:56
问题 When using sinon I just want to replace my function's return value and don't need other infos like how many time it was called. Which one of them is better? sinon.replace(Component.prototype, 'getValue', () => 123); const myStub = sinon.stub(Component.prototype, 'getValue'); myStub.return(123); 回答1: I rarely see sinon.replace being used in many projects. The advantage of using stub is you can modify the return value many times for example. let getValueStub; before(function() { getValueStub =

How to stub https.request response.pipe with sinon.js?

柔情痞子 提交于 2020-12-03 18:03:28
问题 Let's say, that I have this simple code: var https = require('https'); var options = { host: 'openshift.redhat.com', port: 443, path: '/broker/rest/api', method: 'GET' }; var req = https.request(options, function(response) { console.log(response.statusCode); response.pipe(save stream to file with fs) }); req.on('error', function(e) { console.error(e); }); req.end(); Well, I'm bit new with sinon.js and I'd like to ask: How to stub response.pipe()? Of course, I can make stub for https.request

How to stub https.request response.pipe with sinon.js?

余生长醉 提交于 2020-12-03 18:01:57
问题 Let's say, that I have this simple code: var https = require('https'); var options = { host: 'openshift.redhat.com', port: 443, path: '/broker/rest/api', method: 'GET' }; var req = https.request(options, function(response) { console.log(response.statusCode); response.pipe(save stream to file with fs) }); req.on('error', function(e) { console.error(e); }); req.end(); Well, I'm bit new with sinon.js and I'd like to ask: How to stub response.pipe()? Of course, I can make stub for https.request

How to stub https.request response.pipe with sinon.js?

放肆的年华 提交于 2020-12-03 18:01:15
问题 Let's say, that I have this simple code: var https = require('https'); var options = { host: 'openshift.redhat.com', port: 443, path: '/broker/rest/api', method: 'GET' }; var req = https.request(options, function(response) { console.log(response.statusCode); response.pipe(save stream to file with fs) }); req.on('error', function(e) { console.error(e); }); req.end(); Well, I'm bit new with sinon.js and I'd like to ask: How to stub response.pipe()? Of course, I can make stub for https.request

Why is my sinon stub acting like it's calling the real function?

你离开我真会死。 提交于 2020-08-20 10:33:05
问题 I'm trying to follow this example: https://www.alexjamesbrown.com/blog/development/stubbing-middleware-testing-express-supertest/ but the sinon stub doesn't seem to be executing the wrapped code. I've seen lots of stackoverflow posts regarding this issue but none of the answers have helped me figure out what I'm doing wrong. Whenever I run my test I get the following error: 1) should return a list of sites 0 passing (42ms) 1 failing GET /api/config/buildPro/sites should return a list of sites

How to stub express middleware using sinon in typescript?

强颜欢笑 提交于 2020-07-10 10:27:35
问题 I'm trying to write an integration test for my express router using typescript, mocha, sinon and chai-http. This router uses a custom middleware that I wrote which checks for JWT in the header. Ideally, I want to stub my authMiddleware so that I can control its behaviour without actually providing valid/invalid JWT for every test case. When I try to stub authMiddleware in my tests, I realised that express app uses the actual implementation of authMiddleware rather than mocked one. I've tried

How to stub Vue component methods for unit testing

微笑、不失礼 提交于 2020-06-17 04:12:10
问题 How can I stub certain methods (getters, in particular) from Vue single file components for unit testing with mocha/expect? The problem I was facing was the following: I have a component with a get method someData <script lang="ts"> import { Vue, Component } from 'vue-property-decorator' import SomeService from '@/services/some.service' @Component() export default class MyApp extends Vue { ... mounted () { ... } get someData () { return this.$route.path.split('/')[1] || 'main' } get

how to mock configurable middleware in node js with sinon and mocha

纵饮孤独 提交于 2020-06-13 09:07:48
问题 I have configurable middleware where I can pass parameters and based on that it calls next function. middleware code: File: my-middleware.js exports.authUser = function (options) { return function (req, res, next) { // Implement the middleware function based on the options object next() } } var mw = require('./my-middleware.js') app.use(mw.authUser({ option1: '1', option2: '2' })) How to mock the middleware using sinon js? I have done in this way but, it throwing me "TypeError: next is not a