NestJS – Test suite failed to run Cannot find module ‘src/article/article.entity’ from ‘comment/comment.entity.ts’

You can tell Jest how to resolve module paths by configuring the moduleNameMapper option, which is useful if you’re using packages like module-alias or if you’re using absolute paths. Add these lines to your Jest configuration: { // … “jest”: { // … “moduleNameMapper”: { “^src/(.*)$”: “<rootDir>/$1” } } } Now modules that start with …

Read more

unit test mocha Visual Studio Code describe is not defined

Finally!!! After a long search and reading some tutorials and comments I found the solution: the problem was with the config. Open the test config file and delete the following lines: “-u”, <<<< delete this line “tdd”, <<<< delete this line launch.js “version”: “0.2.0”, “configurations”: [ { “type”: “node”, “request”: “launch”, “name”: “Mocha Tests”, “program”: …

Read more

Jest typescript tests runs twice, one for ts files, and one for js files

Is this normal in ts-jest or am I missing some extra configuration You should set roots to /src only. Here is a good config: module.exports = { “roots”: [ “<rootDir>/src” ], “transform”: { “^.+\\.tsx?$”: “ts-jest” }, “testRegex”: “(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$”, “moduleFileExtensions”: [ “ts”, “tsx”, “json” ], } I also only test .tsx? files (no .jsx?) 😉

“constructor” in typescript interface

Where is this library from? Whoever wrote it deserves a stern talking-to. Either it’s a mistake (in which case they never tested it) or it’s intentional but eeeeevil: using the not-quite-reserved word constructor as an identifier for an instance method is just asking for trouble. EDIT 2019-04-25: The trouble is worse than just “this is …

Read more

How to iterate over a Set in TypeScript?

@SnareChops was mostly correct: mySet.forEach(function(item){ // do something with “this” }, **this**); This works. I’m guessing: for(item of mySet.values()){ } Would work if I weren’t working with es-shim stuff which is messing everything up for me. But the shim stuff is prescribed by the Angular 2 crew so ¯_(ツ)_/¯ The only other thing that worked …

Read more