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: