2,811 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
0
answers
39
views
Karma + Jasmin mock query param
I am new to ts and to frontend. I want to write test that mocks query param in uri.
it('should read the query parameter', () => {
const stub = sinon.stub(window.location, 'search').get(() => '?...
0
votes
0
answers
44
views
How to make Sinon stubbing work in a worker inside a Node.js application?
Like I have this set-up
main.ts
import { Worker } from 'node:worker_threads';
function myParentFunc() {
new Worker('worker.ts');
}
worker.ts
myObj.myFunc()
test.ts
const sandbox = sinon....
cis's user avatar
- 1,403
0
votes
0
answers
59
views
How to mock History API using Sinon, Mocha and JSDOM?
I've writing a simple single-page application from scratch, and it has a simple router class. It works fine, and now is time to create unit tests for router. For testing, I use Mocha + Chai + JSDOM.
...
0
votes
0
answers
50
views
Mock exported instances of private classes
I have a class "SomeService" which isn't exported. I export the instance which can be used to call functions on it. Basicly a singleton.
Here the example
export const someService = new ...
1
vote
0
answers
173
views
Why are my tests failing for a WhatsAppbot using whatsapp-web.js? Potential issue with mocks
I have written a WhatsApp bot using whatsapp-web.js, and it works fine in production. However, when I try to run tests, they fail, and I suspect the issue lies with my mocks, but I am not entirely ...
0
votes
1
answer
458
views
in node.js ESM I want to stub an exported module thats the default
I have a very simple auth middleware with an export default () anonymous function:
export default () => async (req, res, next) => {
try {
// some auth implementation... does not matter
...
1
vote
1
answer
48
views
Stub MongoDB calls with Sinon
I am trying test my routes but I can't stub my repository function, I want to stub the function that in the repository that calls the database.
This is my test file:
import { expect } from "chai&...
0
votes
0
answers
33
views
Supertest and Sinon - stubbing same function twice (or more)
I'm unable to user supertest with sinon to stub the same function twice in the same test file. How can I do this?
Here is the code I have currently:
const { app } = require('../../app');
const request ...
1
vote
1
answer
116
views
How do i mock MongoDb Connection and Test it
My DB Class to test
I have a DB class where i encapsulate Mongodb methods to test
import mongodb from 'mongodb';
import dotenv from 'dotenv';
// Comfigure dotenv
dotenv.config();
// eslint-disable-...
1
vote
0
answers
83
views
Stubbing Firestore with Sinon does not work
I'm trying to stub a specific Firestore Document Reference which I want to get with the Firestore get Function with Sinon. Unfortunately I'm not able to make it work. The Function which should call ...
0
votes
1
answer
60
views
API tests are all passing, but still giving a time-out error
I am trying to unit test all of my API calls. Every call passes the test, but i still get an error saying: ✘ Timed out while running tests Failed to exit when running test.js. I have tried adding a ...
-1
votes
1
answer
102
views
Confused if I should use a fake or a stub?
Quite new to unit testing. I am writing unit tests for my code using Chai+Mocha and Sinon and I am stuck at a point because I am not able to decide whether I should use a Sinon stub or a fake. I have ...
0
votes
1
answer
57
views
Make an internal function a stub
Lots of similar questions, but none that seem to fit.
Say there's a nodejs function:
async function handler(event) {
await parseEvent(event)
if(event.a)
await doBusinessLogicA(event)
...
1
vote
2
answers
91
views
How can I stub a function that belongs to a class in an external dependency?
I want to test a Google Cloud Function written in Typescript, and the function calls publishMessage, a member function of the Topic class. How can I make a unit test capture the argument that got ...
4
votes
0
answers
213
views
Stub/mock supabase storage methods
I'm trying to unit tests some custom implemented edge functions with supabase-js.
I'm using Deno and sinonjs for that.
For my edge function i've got multiple scenarios, for the first one I want to ...