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
14 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
17 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
-1 votes
0 answers
11 views

other equivalent to 'require' that can be used in .js files when require part that we added in wdio.conf.js? [closed]

"I am setting up a new WebdriverIO project, and I've noticed that the 'require' statement is not supported in .js files, but it is supported in .cjs files. Is there any other equivalent to '...
Prasad's user avatar
  • 1
0 votes
0 answers
9 views

WebDriverIO Mocha Test: Incorrect Passing with List Item Count Verification [closed]

In a WebDriverIO test using the Mocha framework, the goal is to verify the number of list items on a webpage. The expectation is that there should be exactly 44 list items. However, when I test it ...
Fatma Ben Amor's user avatar
-1 votes
0 answers
23 views

Nodejs Lambda Unit test (mocha/chai)

I have a Lambda function running in a Node.js environment. And I'm looking to write a unit test for this lambda using mocha and chai. When writing the test case, a few questions crossed my mind: ...
vaibhav deep's user avatar
0 votes
1 answer
27 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
30 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
-2 votes
0 answers
40 views

Conflict between "require()" and "import" statement (JavaScript, React, ESM, chai, mocha, supertest)

I know there are many articles that address parts of this issue such as: Javascript, using require() and import in the same file Error [ERR_REQUIRE_ESM]: require() of ES Module not supported https://...
Chris's user avatar
  • 1
0 votes
0 answers
49 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
34 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
58 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
18 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
26 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.1k
0 votes
0 answers
35 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
23 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
20 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
33 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
35 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,803
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
23 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
51 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
47 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
51 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
95 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
9 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
  • 140
0 votes
0 answers
46 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
  • 140
0 votes
0 answers
35 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
44 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
44 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
71 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
0 votes
0 answers
28 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
  • 135
0 votes
0 answers
55 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
84 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,919
1 vote
0 answers
14 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
158 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
14 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,937
0 votes
1 answer
27 views

Mocha test silenty fails because SUT forgot to complete a promise

I've created a simple test case whose complexity is above what I can understand. 😅 This test reproduces a case, where the SUT forgets to complete an internal promise, to which the test has a handle. ...
Samuel's user avatar
  • 6,216
0 votes
0 answers
30 views

how to stub BlobService?

it('should throw error when cloud connectionstring not defined', function (done) { const flow = getDefaultFlow(); var credentials = { "nCloudConfig" :...
Alex's user avatar
  • 1
1 vote
0 answers
49 views

How to force default test runner in WebStorm to be an npm configuration instead of mocha?

I'm using WebStorm 2023.2.1. My org uses a tool called chamber to access secrets when running tests locally. So when we run tests, we actually run chamber, and mocha (plus all of mocha's arguments) ...
Rich's user avatar
  • 1,165
0 votes
1 answer
76 views

How to exclude a file from coverage report in Mocha and Nyc

I have a test setup configured with Mocha and nyc. I'm trying to exclude a certain file from the report. So I tried this: "nyc": { "exclude": [ "./sites/modules/...
ABGR's user avatar
  • 4,803
0 votes
0 answers
23 views

How to write test for VSCode extenstion

I would like to create a test to verify the operation of yoyo.transferUpperCase. I am wondering if I have to create a mock to reproduce getText in the test. However, I do not know how to create a mock ...
kenken's user avatar
  • 1
1 vote
0 answers
126 views

nyc mocha is showing unknown(0%) code coverage with type:module in package.json for typescript

I have used type module for my project in package.json file.now when i added the test with mocha and try to find the code coverage by nyc then it is showing the Unknown 0% coverage for my typescipt ...
Raj's user avatar
  • 11
0 votes
0 answers
26 views

Trying to run a for loop using webdriver-io and mocha gives me "Cannot read properties of undefined (reading 'waitForDisplayed')"

I am trying to loop through a JSON file which of users and test logging in and out as each user, but when trying to use a for loop I get the following error Cannot read properties of undefined (...
Mike Meyer's user avatar

1
2 3 4 5
171