Encountering `error TS2554: Constructor expected 0 arguments, received 1` with ts-jest

I've recently delved back into TypeScript and started implementing TDD. I successfully set up ts-jest to run my tests, but I've hit a roadblock with a seemingly simple issue that has me stumped.

organization.ts:

class Organization implements IOrganization {
    id: Id;
    name: string;

    constructor(name: string) {
        this.name = name;
    }
}


export default Organization;

test.ts:

import Organization from "./organization";
import Simulation from "./simulation";

it('stores the user organization', () => {
    let userOrganization = new Organization("does not matter");
}

While VS Code isn't showing any errors, when attempting to execute ts-jest, I encounter an

error TS2554: Expected 0 arguments, but got 1
in my constructor. It feels like there's something obvious I'm overlooking.

Answer №1

It turns out that my problem was caused by excluding *test.ts* in my tsconfig.json file following the TypeScript example. This exclusion prevented ts-jest from recognizing them. Once I removed this exclusion, everything started working perfectly. Special thanks to Yannick Meeus for assisting me in resolving this issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountered an error while trying to retrieve data from

Having trouble with file uploads to the S3 bucket using @aws-sdk/client-s3 library and encountering errors when uploading files larger than 70kbps: `TypeError: Failed to fetch at FetchHttpHandler.handle (fetch-http-handler.js:56:13) at PutObjectCommand ...

When considering Angular directives, which is more suitable for this scenario: structural or attribute?

In the process of developing an Angular 5 directive, I aim to incorporate various host views (generated from a component) into the viewContainer. However, I find myself at a crossroads as to whether I should opt for an attribute directive or a structural ...

What do "First Class" modules refer to precisely?

Recently, I came across some references to programming languages that offer "First Class" support for modules like OCaml, Scala, and TypeScript. This got me thinking about a comment on SO that described modules as first class citizens in Scala's key f ...

Transferring data from an Angular 2 component to a service

I am trying to pass data from an Angular component to a service and utilize the service's methods to manipulate it. Here is an example: class SomeComponent { public info: Array<any> = MyData; constructor(private myService: TablePag ...

I'm puzzled as to why the banner text for my three images in the slider is only displaying on one of the images, all crammed together

Currently, I am working on an ecommerce project with Next.js. One of the challenges I faced was while setting up my banner page that includes a react-slick slider for images. Initially, when I added just one image, I noticed multiple renderings of it, but ...

How to Retrieve all Implementations of an Interface in Typescript

Is there a way in Typescript to retrieve a list of all classes that implement a specific interface? In .Net, you can achieve this using reflection, but I haven't been able to find information on how to do the same in Typescript. Here's an examp ...

Bringing in Chai with Typescript

Currently attempting to incorporate chai into my typescript project. The javascript example for Chai is as follows: var should = require('chai').should(); I have downloaded the type definition using the command: tsd install chai After refere ...

In what way can TS uniquely handle each element of an array as the key of an object?

I am struggling with an object that I need to have keys representing every item in the array, each linked to a value of any. Can anyone provide guidance on how to achieve this? Unfortunately, I couldn't find a solution. Here is an example for refere ...

Adjusting table to include hashed passwords for migration

How can I convert a string password into a hash during migration? I've tried using the following code, but it seems the transaction completes after the selection: const users = await queryRunner.query('SELECT * FROM app_user;'); user ...

Steps for integrating .web extension files in React Native Web using Typescript

When using react native web, there is a potential to utilize files with extensions such as .web and .android. For example: myFile.web.js myFile.android.js These files can then be included like so: import myFile from './myFile'; React Native w ...

Is it possible for an app's feature module to access routing configurations from another lazily loaded module in Angular routing?

The functionality of our App is divided into multiple feature modules that are lazily loaded. Each module is loaded under different path matches, and some modules import a shared module containing reusable components. Everything seems to be working well so ...

Issues with eventEmitter functionality in Angular 2

Everyone performed admirably following the manual, here is the code snippet for WebSocketBroadcaster: import {EventEmitter, Injectable} from "@angular/core"; @Injectable() export class WebSocketBroadcaster { ee: EventEmitter<any> = new EventEmi ...

Submit the request when the fileReader's onload event is triggered

Do you have any suggestions on how to improve my fileReader for uploading images? I am currently facing an issue where multiple requests are being sent to the server when there are more than 1 image due to a for loop. How can I modify my code to address ...

Transmit information using express handlebars in a straightforward node application

Struggling to pass data from express handlebars to index.html? Check out my code below: server.js code: const express = require('express'); const app = express(); const expressHandlebars = require('express-handlebars'); const path = r ...

Launching a Material UI Modal nested within a parent component

I have a table displaying various teams. Each row in the table has a menu option that, when clicked, should open either a modal or a dialog box. I want to keep the table, menu functionality, and modals as separate components for better organization. Here&a ...

The issue lies in attempting to assign an 'Observable<number[]>' to a parameter expecting an 'Observable<ProjectObject[]>'. This obstacle must be overcome in order to successfully create a mock service

I am currently working on setting up a mock service for unit testing, but I am facing an issue where the observable is not returning the expected fake value. Can someone please assist me in resolving this problem and also explain what might be wrong with m ...

Angular 2 ngSubmit triggers unexpectedly on occasions when it is not supposed to

Currently, I am working on developing an Ionic 3 application with Angular 2 and TypeScript. In the app, there is a form that is responsible for sending data to our server. The issue I am facing is that whenever I click on the following button: <butto ...

What is the most efficient way to transfer data to another page without having to repeatedly retrieve it from a

Looking for a way to pass additional data to another page when clicking on an item. I attempted to extend the father class to the child class, but it significantly slowed down the process due to the frequent class calls. This application is a dashboard w ...

How can we modify array.map to return a unique type signature?

Take a look at these two straightforward functions written in typescript: function generate(): Array<[number, number]> { return [[0, 1], [2, 3]]; } function mutate(input: Array<[number, number]>): Array<[number, number]> { return in ...

The error message "Property not found on type 'Product | Customer' in React Typescript" is indicating that the specified property does not exist on the

I am currently working on a React app using TypeScript where I need to manage data for Customers and Products. To enhance this functionality, I plan to create a form component that can be used for updating either a Customer or a Product. The idea is to pr ...