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

Typescript looping through class type properties

Let’s consider that all “not defined” properties i.e. all properties that are defined in the typescript class like (I wrote “not defined” and not undefined for a reason that will be clear below) class A { prop1: string prop2: number } will not be enumerated by any of Object.keys or this.hasOwnProperty(k) since the autogen javascript … Read more

Defining the inverse of Partial in TypeScript

Mapped types are not all created equal. Homomorphic mapped types preserve modifiers of the mapped type. From the pull request introducing this feature: With this PR we preserve property modifiers in homomorphic (structure preserving) mapped types. A mapped type of the form { [P in keyof T]: X } is homomorphic with T (because it … 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