8,482 questions
-1
votes
0
answers
10
views
How to make Mocha/Chai print compared Set objects?
I compare two Set objects in Mocha/Chai:
expect(new Set(result.controllers)).to.deep.equal(new Set([backendPrincipal, indirectPrincipal]));
Mocha prints unhelpfully:
expect(new Set(result....
0
votes
0
answers
30
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 ...
2
votes
0
answers
87
views
Electron + Mocha + WDIO unable to mock ipcMain calls
Update: Created Minimal reproducible example on GitHub.
I'm having an issue with mocking ipcMain in wdio + electron + mocha. I have a running electron app that I'm trying to e2e test, but I'm unable ...
0
votes
2
answers
51
views
Is there way to override mocha it function?
I am trying to integrate qase.io with cypress. However with Qase, I need to follow below pattern where I need to pass test function along with ID. For eg:
describe('My First Test', () => {
qase(1,...
0
votes
0
answers
24
views
WebdriverIO: can't access window attribute
I'm having trouble accessing the window attribute in WebdriverIO testing.
In the JavaScript code I create a new instance of OpenLayers:
import Map from 'ol/Map.js';
import View from 'ol/View.js';
...
1
vote
0
answers
47
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 ...
-1
votes
1
answer
41
views
Mocha "TypeError: (0 , calc_1.addition) is not a function" when trying to test
I have a simple project structure:
I am trying to test "addition" function inside of the src/calculator.ts
export function addition(a: number, b: number): number {
return a + b;
}
Here'...
0
votes
0
answers
73
views
Mocha chai test cases are not completing due to on sinon stub
Am using a typical node express typescript project, where i have controller and service file, am trying to write simple testcase for controller file, its executes the test case but after that it's not ...
2
votes
0
answers
25
views
running mocha in the context of a npm script works but running it directly from command line does not
So when I run npm run test_w_emulator or npm run test_w_pure
my mocha test completes properly
package.json
"scripts": {
"test_w_emulator": "sh ./test.sh",
"...
0
votes
0
answers
35
views
How to refactor my index.js page so that my db connection isn't called when running tests
I'm building an API and used a tutorial as a basis, but it didn't cover testing, so I'm looking too add testing as I'm going. But when I import my app object into the test it's running all the code (...
0
votes
0
answers
38
views
Error when calling a contract function with web3.js
I'm working on a smart contract test using Ganache and Web3.js. My contract deploys without errors, but when I try to call a function, I encounter an error.
Here’s my code:
const assert = require('...
1
vote
0
answers
33
views
How to mock a node module import in node js
I am using mocha as my testing environment in my node project and Sinon to stub and mock dependencies.
I have a File Factory.js as
import fs from 'fs'
class Factory{
create = async(options) => {...
1
vote
0
answers
34
views
How does one get the ID from the response body with Mocha test, then use that ID and delete the item?
I am creating a location on the API, the location gets created but then populates an ID, this ID changes all the time. How do I write my Mocha tests to get the ID of the created location, even though ...
0
votes
0
answers
35
views
Issues with Mocking S3 Multipart Upload After Migrating from AWS SDK v2 to v3
I'm trying to run a test. It worked fine with AWS SDK v2, but after migrating to v3 using codemod,I'm facing issues.
This is my index.spec.js to test the test using mocha and sinon. My test is getting ...
0
votes
0
answers
32
views
typeerror: callback is not a function - mocha
I am new to typescript and I have written testcases for databaseHelper class to insert or update date. I am getting callback is not a function error. I am making one call to check if agency exists in ...
0
votes
0
answers
14
views
How to Stubbing Azure Client Using Mocha and chai
const { EventHubConsumerClient, earliestEventPosition } = require("@azure/event-hubs");
const { ContainerClient } = require("@azure/storage-blob");
const { BlobCheckpointStore } = ...
1
vote
1
answer
36
views
Mocha works when using classes but not on functions
Working through a Mocha section of modules on Codecademy, I thought I was getting it but when i tried to practice on my computer for a basic function, it's not working.
Clearly I am missing something ...
1
vote
0
answers
24
views
Can I dynamically add a test file in mochajs in browser?
In the documentation I see a connection option.
It adds a script to the html page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
...
0
votes
1
answer
3k
views
How to fix deprecated [email protected] warning on using npm i?
I'm trying to install mocha-junit-reporter 2.0.2 version in my app, which currently uses mocha 10.4.0 version. When I do npm i I get the following error :
npm warn deprecated [email protected]: This ...
0
votes
1
answer
17
views
Mocha test remains running
I'm running mocha tests from node and all of my test cases successfully pass, however, the npm-test command does not terminate once the tests are over. I've simplified my set-up a lot to bring an ...
1
vote
0
answers
88
views
Upgraded to Chai 5.x, converted whole node project to ESM modules, test run fails with unhelpful error messages
I have a node server that was originally written in 2018-19 with require and module.exports syntax. I recently upgraded to Chai 5.1, which meant I needed to convert every file in my project to ESM ...
0
votes
0
answers
42
views
chai.request is not a function when I use .js files
I have this libs installed in my package.json:
{
"name": "22)-tests",
"version": "1.0.0",
"description": "",
"main": "...
0
votes
0
answers
22
views
Issue writing unit tests for a jQuery datepicker plugin
the start of my plugin
(function(factory) {
if (typeof define === "function" && define.amd) {
define(["jquery", "jquery-ui-dist"], factory);
} else {
...
1
vote
0
answers
27
views
Mocha fails to use typescript baseUrl setting for ESM imports
I'm trying to get "absolute" import paths working in our mocha test files. These work fine for our Vite/TS React app.
import { agent } from 'tests/shared/supertest'
I've tried adding ts-node/...
1
vote
1
answer
78
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-...
0
votes
1
answer
357
views
How to make node.js ignore css files
I can't run the tests with Mocha in my vanilla javascript project when I have a CSS file import because I can't get Node to ignore that specific extension.
I get this error:
TypeError [...
0
votes
0
answers
118
views
VSCode Extension Dev: How to add/configure/run a unit test suite (to add to the integration test suite)?
Background: I am experimenting with creating a vs code extension.
Context: I've started using the project you get from the yeoman scaffolding wizard ( e g npx --package yo --package generator-code -- ...
1
vote
1
answer
27
views
Angular's httpClient.get hangs if called from Mocha unit testing with async / await pattern
I have a simple API call inside a service:
async validate(videoId: string): Promise<YoutubeValidationResult> {
try {
const response = await lastValueFrom(this.httpClient.get<{ ...
0
votes
1
answer
83
views
MongoDB URI Undefined in GitHub Actions CI/CD Pipeline Despite Working Locally
I’m having trouble with my GitHub Actions CI/CD pipeline when it comes to connecting to MongoDB. The connection works perfectly in my local environment, but when I run the tests in GitHub Actions, I ...
0
votes
0
answers
221
views
Postman - Async request within Test Function
I've been testing the asynchronous nature of the Postman sendRequest() function and I'm trying to get it working within an pm.test block but my initial efforts are failing
This is the first example to ...
0
votes
0
answers
47
views
Sinon sandboxes not stubbing functions in a controller in a express js app
I tried stubbing functions that were in a controller in an express app and when I called the controller function, assertions I wrote throws an error that the stubbed functions are not called or not ...
0
votes
0
answers
17
views
How to add additional log statement in Mochaawseome reports in cypress [duplicate]
just logging statement which is inside the it block is executing, but not other, i mean if any logging statements displayed in other methods, if i call that method form it block, those methods are not ...
0
votes
1
answer
39
views
How do you document this.field in the Mocha TestContext with JSDoc types in a before() hook so that other it() tests and IntelliJ know what it is?
I want IntelliJ (or any similar IDE, like WebStorm or VSCode) to give me auto-complete for my fields that I define in my test context in a Mocha.js before() hook. I then want to be able to see the ...
0
votes
1
answer
36
views
Why error appears while sending transaction from multiple account?
I am trying to run test of the contract that requires to enter ETH using hardhat and mocha. Test fails in "Allows player to enter" even though everything looks the same for "Allows ...
0
votes
1
answer
45
views
Using Mocha to run unit test for Node.js not working as expected
I am using mocha to run a unit test on my Node.js server code which inserts a user address, reads it and validates data and then deletes the address.
it('Create User Address', function(done) {
var ...
-1
votes
1
answer
75
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 ...
1
vote
1
answer
202
views
Error: Timeout of 2000ms exceeded with test: wts, @web/test-runner
I'm using "test": "wtr", which I presume is web testing runner, which uses mocha but not in the package.json, only in the package-lock.json I can see references to mocha.
I get ...
0
votes
0
answers
33
views
How build mocha fraimwork for browser?
I need to change the code in the project mochajs
I know what I need to do, but I don't know how to build the es module for browser.
I used esbuild the project is not built correctly and does not run ...
0
votes
1
answer
47
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)
...
0
votes
1
answer
33
views
How to verify that element is not visible in webdriverio in mocha javascript
I am currently automating tasks in JavaScript using the WebdriverIO framework with Mocha
How can I verify that an element is not visible in WebdriverIO within the Mocha framework?
I want Javascript ...
0
votes
1
answer
153
views
Mocha-Selenium-JavaScript: TypeError: Cannot read properties of undefined (reading 'reporter')
While integrating Allure reports with Mocha, i am trying to incorporate a takescreenshot function in selenium and to add that screenshot in my Allure reports. Its giving me an error of TypeError: ...
0
votes
0
answers
42
views
How can I get the stack trace of unexpected errors with Chai?
I am using Chai with Mocha. I write tests something like this:
expect(() => f(a, b)).to.throw('Sriharikota we have a problem.')
I want to show the stack trace of the original error when it does ...
0
votes
0
answers
69
views
Ethereum Smart Contract Testing with Hardhat, ethers.js, Mocha -- Bug: "ReferenceError: window is not defined"
I'm following this (https://hardhat.org/tutorial/testing-contracts) tutorial on smart contract testing. Here is the test I've written:
const { expect } = require("chai");
const { ethers } = ...
0
votes
2
answers
275
views
Mocha beforeEach, afterEach etc. hooks running outside describe
My mocha hooks beforeEach, afterEach defined in specific 'describe' blocks are running before 'it' blocks in other 'describe' blocks and files.
I have the following test setup:
A global test file - ...
2
votes
0
answers
149
views
Mocha Unit Test Framework + TypeScript + ECMAScript Modules = `[ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"`
Very simple. I have test/simple.ts:
import assert from 'assert';
import {it} from "node:test";
it('sample typescript test', () => {
assert.equal(1 + 1, 2);
});
I have .mocharc.json. ...
0
votes
0
answers
36
views
ts-node ignore file global.d.ts or tsconfig.json?
I have a nodeJs project with typescript and then a tests for it;
i use mocha do this tests
.mocharc.json
{
"extension": [
"ts"
],
"spec": "tests/*.spec.ts&...
1
vote
1
answer
111
views
mocha --reporter spec Error: No test files found
I can't unit test my Google Cloud Functions in online mode (as defined in the instructions that I followed: https://firebase.google.com/docs/functions/unit-testing): if I navigate to the functions ...
2
votes
1
answer
37
views
Go to definition is not working in some method when I use Puppeteer and Mocha
const puppeteer = require('puppeteer');
describe('test', async () => {
let browser, page;
before(async () => {
browser = await puppeteer.launch();
page = browser....
1
vote
0
answers
755
views
Handling [ERR_REQUIRE_ESM] Error in Mocha Tests with TypeScript Compilation
I’m integrating end-to-end tests into my Angular project and using a stack that includes Selenium, Chai, and Mocha. Since Mocha requires JavaScript, I compile my TypeScript files into JavaScript with ...
0
votes
1
answer
298
views
Debugging Mocha tests in VS Code using launch.json not working
I'm trying to debug my mocha tests in VS Code using a launch.json, but this error shows up:
ReferenceError: before is not defined
I also found that I get these errors when I move around and comment ...