115 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
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
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
259
views
How do i resolve error while using mocha and proxyqure with error message: TypeError: Cannot read properties of undefined (reading 'require')
I am experiencing an error with test suite while trying to stub out a method that queries sql db:below is the code i wrote but i keep getting error: TypeError: Cannot read properties of undefined (...
0
votes
0
answers
55
views
Stub a module which exports a function
I need to replace the function returns by a module.
I'm using CommonJS with nodejs 18.
index.js
const sinon = require("sinon");
const axios = require("axios");
const fs = require(&...
2
votes
0
answers
610
views
How to fix parent context unavailable when using proxyquire with ES6 import statement?
I have the following file to test which is the migration_repository.js
import {getDatabaseName} from "./maria_db_connector"
export default class MigrationRepository {
...
0
votes
1
answer
139
views
Stub a function inside a function without passing it as an argument
I have the following code:
const {compose} = require('./compose');
const complicatedFunction = async function (argA, argB) {
const result = await getValue(argA)
const value = await getValue2(...
2
votes
1
answer
3k
views
How to thrown error in catch block using sinon stub
I am using mocha and sinon for test the node services, In controller I have getToken npm module for getting the token with name and value as parameters and in spec file I trying to send empty name as ...
0
votes
1
answer
1k
views
How to force a return value from a mocked non-exported function using sinon or proxyquire or rewire?
I am just getting started unit testing nodejs. I have been using mocha, chai and sinon.
I hit a snag when I wanted to test a function which is not exported. proxyquire looks good, as does rewire.
...
1
vote
1
answer
687
views
How to call or stub with same imported function with multiple ways
In controller I have imported config file for getting path for userId and secret path location and auth file for getting the userId name and secret value based on that I have redirected to some ...
1
vote
1
answer
4k
views
How to call imported function using proxyquire and sinon
In my controller I have imported the secure util file when I call that util with path as parameter it returns unique Id. but how to call this function in test file using proxyquire and stub.
...
2
votes
1
answer
4k
views
TypeError: AWS.SecretsManager is not a constructor in unit testing with proxyquire
I have written a test code to test code that gives credentials from AWS Secret Manager. I used proxyquire and sinon for stubbing and getting this error.
Function I want to test
exports....
0
votes
1
answer
2k
views
Proxyquire not overriding exported function
I have a class modules/handler.js, which looks like this:
const {getCompany} = require('./helper');
module.exports = class Handler {
constructor () {...}
async init(){
await ...
0
votes
1
answer
456
views
proxyquire Error: ENOENT: no such file or directory, scandir
Hello I am new to testing with mocha/chai/sinon and sequelize-test-helpers
Trying to use proxyquire to override the require but having issues
Getting this following error about the path:
Error: ENOENT:...
0
votes
1
answer
267
views
How to Mock non-existent file import in nodejs Lambda
I am facing issue in testing where My logger is in lambda layer thus non-existing for nodeJs import in lambda.js during mocha-chai testing. I tried mock-fs but getting errors Can not find module /opt/...
0
votes
1
answer
2k
views
How to mock 'request' with proxyquire
I have a file foo.js
var request = require('request');
module.exports.getRequest = function (url, headers) {
return new Promise((resolve, reject) => {
request(
{
...