Questions tagged [mocha.js]

Mocha.js is a feature-rich JavaScript test framework running on Node.js and the browser.

mocha.js
Filter by
Sorted by
Tagged with
0 votes
0 answers
7 views

How to use mocha unit test chokidar watch events

I have the following pieces of nodejs code: const watcher = chokidar.watch(path, { persistent: true }); console.log("bbbb"); watcher .on('add', path=> { // do something; }) .on(...
Jean's user avatar
  • 1
0 votes
1 answer
15 views

How to test a text handler in telegraf.js

I am unable to test the text handler in telegraf.js. I have a listener that is set in the class constructor. this.on(message.message('text'), async (ctx) => this.processText(ctx)); I am trying to ...
agentx's user avatar
  • 9
0 votes
0 answers
18 views

How to run different mocha test files one after another or more than 5 files in parallel?

I am trying to make a Test Automation Cases with Mocha js, and facing an issue. When I try to run mocha test files parallel I can not run more than 5 files and if I try to run without the parallel ...
R000000T's user avatar
0 votes
0 answers
20 views

NodeJS: MongoNotConnectedError: Client must be connected before running operations

I am experiencing MongoNotConnectedError: Client must be connected before running operations using Mocha to test in NodeJS. In the output it shows database has been connected successfully while ...
Leyan T's user avatar
0 votes
0 answers
15 views

How can I integrate a custom Mocha reporter into my test suite to filter out or ignored specific test cases from the test report based on tags?

I need guidance on integrating a custom Mocha reporter into my test suite to effectively filter out specific test cases from the generated test report based on tags. Specifically, I require a solution ...
Hamza Naveed's user avatar
0 votes
0 answers
27 views

why could be my mock of dynamodb scanCommand with aws-sdk-client-mock is returning undefined?

I'm doing a function which scan a table and the I use this function inside other in order to execute an elimination of data. When I do the unit test and I try to mock the scanCommand, it always send ...
EddaK's user avatar
  • 1
0 votes
0 answers
18 views

beforeEach on Mocha does not reset object

I have the following in state.js: var state = {}; function getState() { return state; } function setItem(key, value) { state[key] = value; } function resetState() { state = {}; } exports....
darkhorse's user avatar
  • 8,478
2 votes
0 answers
24 views

Dynamically generate data-driven Mocha tests using the data obtained before method

I'm attempting to dynamically generate test cases based on the data retrieved from an API. Below is the Mocha test class: describe('Test suite A', function() { var serviceClient: ServiceClient; ...
pooventhan's user avatar
-1 votes
0 answers
18 views

Cannot find name 'browser'.ts(2304)

I used webdriverIO and Mocha as e2e test tools. types field in tsconfig.json configured like the below: "types": ["node", "webdriverio", "@wdio/mocha-framework",...
statust's user avatar
0 votes
0 answers
46 views

Redis connection refused only when using test containers

I am trying to get test containers and redis to work with a Node.js application that is using BullMQ to create some queues. I am getting connection refused when running tests but it works when running ...
joshk132's user avatar
  • 1,023
0 votes
1 answer
80 views

How to run mocha with the tsx TypeScript runner

I'm using the tsx command (similar to ts-node) to run all my TypeScript code. How can I use tsx to run my Mocha test suite?
Jo Liss's user avatar
  • 31.5k
0 votes
0 answers
24 views

Creating Mocha test suites programmatically

I'm currently initializing a Mocha instance, to which I add files: const mocha = new Mocha({ ui: "tdd", color: true, }); const testsRoot = path.resolve(__dirname); mocha.addFile(path....
LppEdd's user avatar
  • 20.6k
0 votes
0 answers
49 views

Getting error in my nestjs project with mocha and chai: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for

I just simple create project using below commands: npm i -g @nestjs/cli nest new project-name npm install --save-dev mocha chai @types/mocha @types/chai package.json: { "name": "...
Vishal Kamal's user avatar
  • 1,114
0 votes
0 answers
12 views

supertest mocha Why I get success test passing although expected fails?

I use supertest and mocha and all works but I got one problem. If I use the expect function and it fails my test says still its passing but this is false it should show an error and not passed. What I ...
festlest's user avatar
0 votes
0 answers
51 views

No "exports" main defined in @wdio/utils package

I have upgraded my project from Wdio version 7 to 8. I am using a yarn version 4 with PnP. While all packages are installed and all of them are stored in the cache folder, I am not able to run my ...
user20332896's user avatar
-1 votes
1 answer
43 views

Can we use sinon.stub without using async function in the API

I'm running unit testcases using mocha chai and using Ssnon.stub method to mock my DB functions inside the API and am not using async function in my API. When I try to run testcase it's getting timed ...
Johnson Anthony's user avatar
0 votes
0 answers
19 views

Mocha test html report is not generating for all test files in visual studio code throwing an error as windows can not find the test file

Mocha test html report is not generating for all test files in visual studio code throwing an error as windows can not find the test file.(refer the attached screenshot) Report is generating for ...
Saroj Sahoo's user avatar
0 votes
0 answers
16 views

Getting error while running unit test in Vue (mocha and chai)

I've recently upgraded my Vue application to webpack 5 and getting the error as shown in the screenshots. vue.config.js after upgrading the application to webpack 5: when I run test command, it gives ...
Jappreet's user avatar
  • 387
0 votes
0 answers
32 views

Pulumi (Typescript) Unit Testing: `pulumi.Config()` returns empty object under test

I am using mocha to unit test my pulumi code. I was able to test and mock my resources by injecting a custom pulumi.runtime.Mocks. However, when I start using pulumi.Config() with some required fields,...
Ken's user avatar
  • 641
0 votes
1 answer
53 views

Unit Testing Firebase Cloud Function 2nd Gen: makeDataSnapshot refPath does not works

When creating a test using mocha for the following cloud function //index.js exports.cloudFnTest = onValueCreated({ timeoutSeconds: 30, memory: '128MiB', instance: "test-instance", ...
Stormbreaker's user avatar
0 votes
0 answers
15 views

Mocha API testing | Share data between test suites in parallel testing

We are using mocha to test APIs end to end. In the project we have around 100+ tests suites and each test contains several tests. I have POM structure where tests are using helper methods to call the ...
lazy_coder's user avatar
0 votes
1 answer
49 views

postgresql insert statment taking 240+ ms to run for single insert in typescript express app

I am trying to test a db insert operation using mocha for an node.js express application that uses fp-ts and pg npm package. I am running on my local machine and the db is in the digital ocean cloud. ...
user1790300's user avatar
  • 2,033
1 vote
1 answer
49 views

Trigger multiple test using MOCHA

Context: My test folder automationSuite\apiTestSuite has around 4 test files userAPIValidation.js orderAPIValidation.js verifyAPIEndPoints.js verifyHealthEndPoints.js And also I am using the mocha ...
Jyoti Prakash Mallick's user avatar
0 votes
1 answer
47 views

Can't get parameters in v2 function with firebase-functions-test

I have a v2 onCall function: import { HttpsError, onCall } from "firebase-functions/v2/https"; import { logger } from "firebase-functions"; import { getAuth } from "firebase-...
Reid Moffat's user avatar
0 votes
0 answers
144 views

Node JS typescript project: running tests with Mocha and using @swc-node

I am trying to learn Node JS, to build a REST API. Coming from a Python background, this is quite challenging. My issue is: I am trying to set up automated testing using Mocha. To do this, I have the ...
Compphys's user avatar
0 votes
0 answers
21 views

Creating a Stub Instance Using createStubInstance: Constructor Not Skipped as Expected

I have the following problem: I have a class, which is a State controller and I want to test it when its in the "start" state. In particular its update method, which switches to the next ...
Krblaze's user avatar
0 votes
0 answers
16 views

Clearing caches of libs during tests and moving to ESM from common.js

Issue: https://github.com/web-push-libs/web-push/issues/772 (look at last 2 comments) File in question: https://github.com/web-push-libs/web-push/blob/master/test/testSendNotification.js I am having ...
Senbar's user avatar
  • 41
0 votes
0 answers
9 views

How exclude paths from Mocha using regexp

I'm using mocha to run unit test in a project with multiple modules, sometimes including node_modules. src |_module1 |_dir |_test |_unit |_module2 |_dir |_test |_unit |_module3 |_dir ...
Mezoo's user avatar
  • 719
0 votes
0 answers
55 views

Mochawesome Report add context

I am using Mocha to run my test cases in a tool that I have built. To generate the report a use Mochawesome. Now I need to add information to the HTML Report. I have my test case: describe('INTWL ...
BlueReddington's user avatar
0 votes
0 answers
19 views

Trying to use this.wdioRetries, but always get it's equal to 0

my code snip: (test should fail and start a retry) let utils = require("../utils/utils"); const { default: newFlowScreen } = require("../../pageobjects/flow/general/createFlowScreen&...
Opal Lavi's user avatar
0 votes
0 answers
7 views

Mocha Rerun Tests X amount in script

I have my mocha command to execute in Node configured in my package.json file **"NightBuildRegretionExecution":** "mocha ./Test/**/test.js --timeout 100000 --parallel --reporter ...
BlueReddington's user avatar
0 votes
2 answers
84 views

Chai assertion includes or for string [duplicate]

I am trying to traverse through a list of elements and want to assert that the body includes either of the 2 values. I am trying to use the following but it only lets me assert one value. expect(...
Akash Jain's user avatar
0 votes
1 answer
30 views

Testing with Mocha, ReferenceError: alert is not defined

I am trying to do a test where this calculator app will return a false and show an alert message when invalid entries are given. However, I keep getting this error message: 1 failing 1) checkNum ...
Nicole's user avatar
  • 35
0 votes
0 answers
10 views

Returned an undefined when resolving JWTVerifyStub- Mocha/Chai

I'm working on creating test scripts for my validateAuth function, but I've encountered an issue where I'm getting an undefined value from this line of code const {_id} = jwt.verify(token, process.env....
DustBoy's user avatar
  • 143
0 votes
0 answers
25 views

nyc branches coverage showing 100 (0/0) or 50 (3/6)

The Nyc branch coverage seems to be a bit off to me. I think it is giving me wrong branch coverages.The value and the tests dont seem to be valid to me. We recently upgrade our legacy app from ...
Vah Run's user avatar
  • 12.2k
0 votes
0 answers
19 views

passt test resulsts from postman/newman to mocha

I try to integrate my http tests from postman with newman into mocha so that they show up as test results. The main problem i am facing is, that i cant define in mocha test cases asynchronous. But ...
Marc's user avatar
  • 3,188
0 votes
0 answers
65 views

Static import works, but dynamic import of same module fails

I have a small bit of frontend code that is tested by Mocha. In relevant part, it looks like this: export const functionUnderTest = async () => { const module = require('./index'); }; I need to ...
SuperNova's user avatar
  • 111
0 votes
0 answers
31 views

Unit test code fails by stating UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object in node js with mocha chai

index .js module.exports = { addDetails: function() { let data =[] data.push("one"); return data }, deleteDetails: function() { let data =["one" , "...
Upendra Pradhan's user avatar
0 votes
0 answers
80 views

How to Test route from useRoute in a Vue.js 3 Composition API Component?

I'm facing challenges in testing a Vue.js 3 component that utilizes the useRoute from the Vue Router within the Vue Test Utils, Mocha, and Chai framework. My component is written using the Composition ...
Андрей Кондратов's user avatar
0 votes
1 answer
167 views

VScode Mocha Test Explorer: Worker Error: No test files found: {}

Trying to load/run tests from VScode with Mocha Test Explorer, but it fails with a mocha error while loading my tests. I added this to settings.json "mochaExplorer.mochaPath": "/...
Dave Deasy's user avatar
0 votes
0 answers
83 views

Node.js Lambda function unit test using mocha/chai

I have a Lambda function in a Node.js environment which returns a success response as follows: { "moduleName": "getVVTags", "message": "[\"6.9.0\",\&...
vaibhav deep's user avatar
0 votes
0 answers
62 views

Access testData from beforeEach for parameterized test

I do want to create test data in the beforeEach method and access that data to give to the parameterized test but I get an error TS2454: Variable  testData  is used before being assigned. describe('...
Teharez's user avatar
  • 563
1 vote
1 answer
37 views

Constructor mock not working in mocha unit test in Javascript

I am trying to raise an exception for an constructor method of EventHubBufferedProducerClient but its not working as expected. Am I missing something here. My class method: import { ...
Prabhakaran's user avatar
  • 1,294
0 votes
0 answers
19 views

mocha uncovered lines data loading problem

Hello dear stackoverflow users. I am developing an application with react and typescript. In this application, I write my tests with mocha sinon chai. After my test runs, I see these lines in ...
İsmail Cem Altekin's user avatar
0 votes
0 answers
155 views

Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves

I'm trying to write tests for my node.js API but they keep failing with the above error. I'm running mongodb in a docker instance and mongoose as driver. So far i've tested that the connection to ...
Mando's user avatar
  • 1
0 votes
0 answers
15 views

Writing a Test for an API call with Http CallableContext using Mocha in Typescript

I have the following method async addNonAppUserToGroup( data: any, context: functions.https.CallableContext ) { const userId = context.auth?.uid ?? context.auth?.token.user_id; functions....
Kingsley Simon's user avatar
0 votes
0 answers
20 views

TypeError: callback is not a function. How to transform this mocha test to async testing?

This is a simple web application which manages resources. I am using MongoDB and Mongoose for database and I am trying to test the findOne() mongoose function. It takes a property as a parameter and ...
hokkyo's user avatar
  • 13
0 votes
1 answer
85 views

Mocha: tests cannot find module

I have a very simple unit test that starts in these lines: import {SOUTH_EVENTS_ENUM, SouthEventsManager} from "@app/common/south_events_manager"; import {expect} from "chai"; ...
CrazySynthax's user avatar
  • 14.4k
0 votes
0 answers
130 views

Can't mock imported function in ESM Modules mocha

So I've been trying to mock an imported function for a file that uses external calls to DB, redis, and etc. So I can isolate only the methods of a class that uses that function. In production we are ...
Jay's user avatar
  • 29
0 votes
0 answers
54 views

Mock Redis, but can not find the result

I'm currently doing unit test with mocha.js, sinon.js and chai.js. When testing, I mock redis to createClient. Here is the code I want to test: async setAsync(key, value, ttl) { return await ...
Ken  Chang's user avatar

1
2 3 4 5
171