Questions tagged [mocha.js]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
5 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
  • 707
0 votes
0 answers
10 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
8 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
5 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
54 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
17 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
-1 votes
0 answers
39 views

why require() is not supported in my terminal cmd?

var expect = require('chai').expect //const expect =import('chai').expect const platzom=require('..').default describe('#platzom',function(){ it('si la pabra termina en ar se le quitan estos 2 ...
LuffAce's user avatar
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
17 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
  • 11.8k
0 votes
0 answers
13 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,130
0 votes
0 answers
28 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
27 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
38 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
45 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
37 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
52 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
  • 541
1 vote
1 answer
35 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
15 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
75 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
12 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
19 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
31 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.2k
0 votes
0 answers
54 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
26 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
0 votes
0 answers
29 views

Is there a way to call mysql query from WebdriverIO/Mocha/Javascript frmaework test case?

Not able to call sql query from it block Not even executed db.query statement but simply test passed **Here is the code block ** var db = require("../utils/db"); it("DB Testing", (...
Hariprasad KS's user avatar
0 votes
0 answers
49 views

How to run sql script from webdriverIO Tests

I wanted to fetch the data from the database and use that data to verify from my application. I got code to connect DB and fetch it but this is with individual database.js file only. The problem here ...
Hariprasad KS's user avatar
0 votes
0 answers
42 views

async method reducing the coverage under branches

Here's my code: it('test method', async () => { const self = {} const a = await identityModule.init(self); expect(a).to.equal("abc") }); Note that the coverage is 100% ...
ABGR's user avatar
  • 4,839
0 votes
0 answers
12 views

Javascript AssertionError for database objects with generated timestamps

I'm asserting that the data fetched from my database contain the below objects but my assertionError seems to show that the objects aren't included. My query is being logged to the console, showing ...
Nkechi Anyanwu's user avatar
0 votes
0 answers
27 views

Why does supertest work on my local machine but not in a bitbucket pipeline?

While running supertest in a bitbucket pipeline I get the following issue: Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ...
Davy Vos's user avatar
0 votes
0 answers
56 views

How to set up Mocha with Instanbul coverage for ESM code in 2023?

I am almost done shaving a yak, but this one has me stumped... My code base and the tests are ES6 code. All tests are running as expected through Mocha, but I cannot get coverage. All I get is: -------...
Michael Jonker's user avatar
0 votes
1 answer
51 views

Can I use dynamic imports to load test suite modules into mocha?

I have been structuring my tests with commonJs using the following structure; // My main file describe('unit tests', function(){ require('./unit/test.spec.js'); }) describe('functional tests', ...
Michael Jonker's user avatar
0 votes
1 answer
75 views

Puppeteer testing - CdpElementHandle.click() doesn't seem to work

I am trying to gain some basic understanding of how Puppeteer works and am struggling big time. The app I am testing could be found here. Upon clicking on the Login button the app should redirect to ...
karalkal's user avatar
0 votes
1 answer
124 views

Cannot use import alias in component tests

I'm trying to use simple React component tests with WebdriverIO, Mocha and TypeScript. I met an issue specifically related to using import aliases in WebdriverIO. I have simple template components and ...
Medvedscak's user avatar
0 votes
0 answers
13 views

Mocha --file with mochaHooks works on CLI but not as file property in .mocharch.json

In package.json the following script works perfectly for running my mocha tests without any issues. This includes specifying my implementation of a global beforeAll hook via -file src/tests/...
MarkE's user avatar
  • 150
0 votes
0 answers
58 views

How to generate JUnit Report along with along with allure report generated by using allure-mocha?

In a typescript test-only project which uses Mocha framework to run the tests, allure-mocha to generate an allure report, I am trying to generate a junit report along with the allure report. I tried ...
Chandra's user avatar
0 votes
0 answers
19 views

Why doesn't mocha with hooks work with VS Code debugger?

Since adding a global beforeAll hook to my mocha unit tests they fail to work when launched via a launch.json debugger configuration. The following test script in my package.json works fine to execute ...
MarkE's user avatar
  • 150
0 votes
0 answers
48 views

ERROR @wdio/runner: Error: A "user" or "key" was provided but could not be connected to a known cloud service

ERROR @wdio/runner: Error: A "user" or "key" was provided but could not be connected to a known cloud service (Sauce Labs, Browerstack, Testingbot or Lambdatest) When I run My Code ...
Shemul Hasan's user avatar
0 votes
1 answer
53 views

How to perform a unit test on the controller layer in a nodejs project with mocha and sinon?

I'm creating an API as a study. I'm very new to programming. I wanted to unit test the controller layer using mocha. I'm using dependency injection with the tsyringe library. In the test I wanted to ...
Thiago Henrique Cunha's user avatar
0 votes
1 answer
45 views

mocha chai passes the test even if result is not as expected

I use mocha, chai, express to test REST API response the response status is 201 and I expect to fail the test it('janus post', () => { request('https://***') .post('/***') .attach('file', ...
shuriksun's user avatar
0 votes
0 answers
24 views

How to cover Snowflake connection error in mocha test nodejs

I have written a code to get data from SnowFlake using NodeJS (Lambda). Now I am working to cover the code with Mocha test - this is the part I am new at. I have been able to cover the SUCCESS case. ...
rahul mukherjee's user avatar
0 votes
0 answers
42 views

CI/CD downloading files in the test is completed by assigning the .crdownload format

The main problem is the following: when going through pipelines, a file should be downloaded, but during the passage the file seems to be not completely downloaded or is at some stage at all and a ...
Sergei Buryi's user avatar
0 votes
0 answers
102 views

Starting the MongoMemoryServer Instance failed error

I am trying to test an api using mongodb-memory-server, mocha, chai and supertest, Below is my code: const { MongoMemoryServer } = require("mongodb-memory-server"); const mongoose = require(&...
David Ojetola's user avatar
1 vote
0 answers
40 views

Mocha with import.meta

I would like to implement mocha and chai as my testing library (for unit tests only). The project is all in typescript and consists of a server bundle, and nested within there is a client bundle which ...
kmars's user avatar
  • 155
0 votes
0 answers
58 views

Gitlab CI/CD downloading files in the test is completed by assigning the .crdownload format

Project structure enter image description here. Initializing the driver in the basepage class and specifying the option to the google chrome browser using download.default_directory so that any ...
Sergei Buryi's user avatar
0 votes
2 answers
103 views

Ethers function not found

I’ve just been going through the documentation of hardhat and I ran into an issue early on. When I try to deploy using the below hardhat function: async function deployTokenFixture() { const ...
FortuneSeeker's user avatar
0 votes
2 answers
17 views

How to not send sms or emails when running mocha test suite

I'm running end-to-end tests with Mocha, but I do not want SMS or emails to be sent by the test suite. What is the best practice for skipping over these functions if testing, and running them when in ...
ajbraus's user avatar
  • 2,929
1 vote
0 answers
16 views

Parsing from a json file in webdriver.io w/mocha isn't working as intended because the dragEvents do not actually drag the parsed names

What I can't seem to figure out is why I keep getting an error "Cannot read properties of undefined (reading 'find') while trying to parse a json file. The parsing will pull in x number of fields ...
STFC's user avatar
  • 11
0 votes
1 answer
193 views

Webdriverio Typescript TSError: ⨯ Unable to compile TypeScript:

I am facing an issue with WebdriverIO and Typescript where I keep getting compilation errors. I tried importing $ and $$ explicitly in the test files but it still doesn't work tsconfig.json "...
Ashlin Karkada's user avatar
0 votes
0 answers
29 views

How to export a delay for unit testing

I am attempting to test if an API retry is happening with the appropriate amount delay. In my client, I have the following code. if (isExpBackOffStatusError) { // retry with exp backoff ...
Sujitt Rameshkumar's user avatar
0 votes
0 answers
18 views

"Invalid Array Length" when running mocha tests with --reporter Progress

When running my unit tests with the --reporter Progress option I'm getting an error as below. When I remove the reporter option, all tests complete fine. RangeError: Invalid array length at Runner....
Ya.'s user avatar
  • 1,947

1
2 3 4 5
171