Experiencing an issue with Jest - Error: unable to access property 'forEach' of null

After watching some tutorials, I decided to create a sample project in Jest for writing tests. In a TypeScript file, I included a basic calculation function like this:

Calc.cs

 
export class Calc {
    public add(num1: number, num2: number): number {
      return num1 + num2;
    }
    public subtract(num1: number, num2: number): number {
      return num1 - num2;
     }
  }

Then, I proceeded to add a test file with the following content:


import { should } from 'chai';
import { Calc } from './Calc';

should();

let calc = new Calc();
test('adds 1 + 2 to equal 3', () => {
    expect(calc.add(1, 2)).toBe(3);
});

Upon attempting to run the tests using npm t command, an error occurred, displaying the following message:

PS C:TestProject> npm t

[email protected] test C:TestProject jest

C:TestProject\node_modules\jest-haste-map\build\crawlers\node.js:49 names.forEach(file => { ^

TypeError: Cannot read property 'forEach' of undefined at default.readdir (C:\TestProject\node_modules\jest-haste-map\build\crawlers\node.js:49:13) at go$readdir$cb (C:\TestProject\node_modules\jest\node_modules\graceful-fs\graceful-fs.js:149:14) at FSReqWrap.oncomplete (fs.js:135:15) npm ERR! Test failed. See above for more details.

The specific file causing the error was traced to be located at node_modules\jest-haste-map\build\crawlers\node.js. Further details regarding the error can be found by accessing the link below:

node_modules\jest-haste-map\build\crawlers\node.js

Answer №1

An error can occur due to a specific reason: ensure that you are in the right directory.

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

Ways to eliminate the initial digit of a decimal number if it is less than 1

I need assistance with modifying float values by removing the first number if it's lower than 1 In the "OPS" table section, I am calculating the sum of OBP and SLG obtained from a database. https://i.sstatic.net/cYwwW.jpg See the code snippet below ...

Streaming RTMP video through a WebView

Currently, I am working on implementing rtmp streaming using WebView. To achieve this, I referred to the code provided on Stack Overflow under this link The easiest way to play an audio RTMP stream in Android, which was shared by a user named Club. After a ...

Searching for real-time data with ajax. Strategies for showing alternative results when there is no user input

I am currently working on developing a live search feature using technologies like ajax, jQuery, PHP, and MySQL. The user inputs certain queries which are then sent to form_livesearch.php where the search is processed. I have successfully implemented this ...

AngularJS does not recognize Model as a date object in the input

I am attempting to utilize AngularJS to showcase a date using an input tag with the type attribute set to date: <input ng-model="campaign.date_start" type="date"> Unfortunately, this approach is resulting in the following error message: Error: err ...

Enhancements to a NativeScript Application

After running some tests on my NativeScript app following the steps outlined here - , I found that it takes 18 seconds for the program to start and for a user to log in. Is this considered acceptable performance? Appreciate any feedback provided! ...

Is there a way to keep a label in a Material-UI TextField from getting obscured by an adornment when the input is not in focus?

Here is the code for my custom TextField component: <TextField fullWidth: true, classes, helperText: errorText, FormHelperTextProps: getInputProps({ error }), InputProps: getInputProps({ error, endAdornment: error ? <Warning ...

What is the process for removing a registered user from Realm Object Server with the use of the Javascript library?

I have been searching online for a solution, but I haven't been able to find an answer. I am attempting to remove a user from ROS, however, I cannot locate a designated API for this task. The version of my realm-js is 1.10.3. If this feature does not ...

Encountered an issue while installing npm packages - found node modules but no package-lock.json

I'm encountering an issue during my npm installation process and I could use some assistance or advice. ELIFECYCLE ENOENT spawn bash <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dda4b2afb6b4b89deff3edf3ed">[email  ...

When attempting to set a JSON array in state, the resulting JavaScript object does not display correctly

As part of my experimentation with fetch APIs in react, I have set up a server that provides dummy data. In the componentDidMount lifecycle hook of my component, I am making a fetch call to retrieve the data. componentDidMount(){ axios.get('http:// ...

Can next.js rewrites be configured with environment variables?

Currently, I am in the process of developing my application with a next.js frontend and express.js backend. During development, I simply run the relevant dev servers in the terminal. However, now I am looking to deploy my app using Docker for production. I ...

Tips for composing content on a sanitized input?

In my small application, I have a feature where a question is displayed with certain words hidden and needs to be filled in by the user. The format of the question looks like this: The {0} {1} {2} his {3} off To achieve this functionality, I wrote the f ...

What are the best ways to optimize and capitalize on functionality in Electron.js?

After creating three custom buttons for the close, maximize, and minimize functions in Electron.js, I encountered an issue. While the close button is functioning properly, I am struggling with implementing the maximize and minimize buttons. In fact, I have ...

Conceal the Angular Material toolbar (top navigation bar) automatically when scrolling downwards

In my Angular application, the main navigation consists of a standard toolbar positioned at the top of the page. My goal is to have this navigation bar smoothly scroll up with the user as they scroll down, and then reappear when they scroll back up. I at ...

Interacting with wpdb using AngularJS

I just started learning AngularJS and I'm eager to implement it on my WordPress website. My goal is to display a table with data from a database in my WordPress site, but I am encountering difficulties accessing the WordPress functions and variables. ...

How can I organize the selected options from a select2 form element using a basic sorting method?

I am utilizing select2 by ivaynberg and encountering an issue with the data arrangement upon submission. Is there a method to have the results in the form submit data reflect the order in which they were selected in the select2 element, without relying on ...

Create styles for each component based on their specific props when designing a customized Material-UI theme

I am having trouble styling the notchedOutline of a disabled <OutlinedInput /> in my custom MUI theme. My goal is to make the border color lighter than the default color when the input is disabled. Here is what I have attempted so far: const theme = ...

Extra Pathway

Having trouble adding a second route to the /privacy page. The error "Cannot GET /privacy.html" keeps popping up. Any suggestions? This code seems to be failing to display the privacy.html content app.get('/privacy', function(req, res) { res.s ...

Send an API call for every item in a given list

There is a function that I am working with: updateCustomers = (input) => { //let urls = input; let urls = [{ name: "localhost:8081", url: "http://localhost:8081" }, { name: "localhost:8082", url: "http://localhost:8081" }, { ...

What steps can I take to resolve the Angular JS error message: [$injector:unpr]?

index.html <!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8"> <title>Angular JS</title> <script src="lib/angular.min.js"></script> ...

Breaking apart field values in React Final Form

In my react and redux application, I am using react final form with a 'cars' field that is a select. When the submit event is triggered, it should only return specific types like coupe: ['BMW'] instead of just the field name with values ...