“Navbar refers to a value, but is being used as a type here” when trying to render a shallow copy of my component when testing

Have you tried to change the name of the file? MyComponent.test.tsx Also, did you install the types of jest and stuff npm i -D @types/jest. I mean I’m saying this because if you look at the jest config where it says testRegex. You have it like this __tests__/*.(test|spec).tsx the test must be inside a tests … Read more

How to preview picture stored in the fake path in Angular 2/Typescript?

This should do what you want: <input type=”file” (change)=”readUrl($event)”> <img [src]=”url”> readUrl(event:any) { if (event.target.files && event.target.files[0]) { var reader = new FileReader(); reader.onload = (event: ProgressEvent) => { this.url = (<FileReader>event.target).result; } reader.readAsDataURL(event.target.files[0]); } }

@typescript-eslint/eslint-plugin error: ‘Route’ is defined but never used (no-unused-vars)

The solution is to disable the native no-unused-vars so that only the TS one is enabled. The former is likely to be enabled if you extend a config in ESLint. Add the rules below to your ESLint config. “rules”: { “no-unused-vars”: “off”, “@typescript-eslint/no-unused-vars”: “error” }

Typescript: Property ‘src’ does not exist on type ‘HTMLElement’

Because src is not a property of the HTMLElement type, but of HTMLImageElement. If you are certain you’ll get an img element, you might want to declare your variable with the correct subtype: element: HTMLImageElement; /* Defining element */ // … this.element = document.createElement(‘img’); /*creating a img*/ Also, you might want to have a look … Read more

Typescript: Type ‘string’ is not assignable to type ‘”numeric” | “2-digit”‘ in Date::toLocaleDateString()

When you initialize a class property with a literal such as public foo = { bar: ‘a’ }, its type becomes { bar: string }, even if you declare it as readonly. TypeScript on purpose doesn’t make the type too strict ({ bar: ‘a’ }). Method toLocaleDateString accepts an object whose key year must be … Read more

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

How do you use Istanbul Code Coverage with transpiled Typescript?

TL;DR: There is a tool: https://github.com/SitePen/remap-istanbul described as A tool for remapping Istanbul coverage via Source Maps The article on Sitepan describes it in more detail: Intern as well as other JavaScript testing frameworks utilise Istanbul for their code coverage analysis. As we started to adopt more and more TypeScript for our own projects, we … Read more