Categories
Mastering Development

Property ‘toBeInTheDocument’ does not exist on type ‘Matchers

Trying to setup testing for a components library. I’ve tried many example and all similar threads on this with no luck. My setupTests.ts file is correctly being loaded (proven with a console.log), and the library seems to be available as if I add import { toBeInTheDocument } from ‘@testing-library/jest-dom/matchers’ and log toBeInTheDocument it is present. […]

Categories
Mastering Development

Cannot read property ‘fromJSON’ of undefined while testing in Jest

while running jest i get the following error.I dont know why am i getting this error. TypeError: Cannot read property ‘fromJSON’ of undefined at Object. (node_modules/@grpc/proto-loader/node_modules/protobufjs/ext/descriptor/index.js:3:66) at Object. (node_modules/@grpc/proto-loader/build/src/index.js:23:20) Below is the tsconfig.json { “compilerOptions”: { “target”: “esnext”, “module”: “commonjs”, “outDir”: “dist”, “sourceMap”: true, “moduleResolution”: “node”, “declaration”: true, “experimentalDecorators”: true, “allowSyntheticDefaultImports”: true, /* Allow default […]

Categories
Mastering Development

Mocked `fs.createFileSync` and `fs.unlinkSync` are not getting called

I have a function that does a lot of things, but among them is that it copies a file to a special directory, does something with it (calls something to interact with that file without using the fs module), and then deletes the copied file once finished. import { copyFileSync, unlinkSync } from ‘fs’; myOtherFunction(path: […]

Categories
Development

I am studying the TS tuples, what’s wrong with this code?

The typescript tuple not worked as I wanted. tsc version 3.6.4 1、When I initialize a tuple like the following: let x: [string, number]; x[0] = ‘John’; and got the following javascript through tsc: var x; x[0] = ‘John’; now run with node, I got this error: /home/peng/ts-learnings/dist/tuple.js:2 x[0] = ‘John’; ^ TypeError: Cannot set property […]

Categories
Development

Typescript cannot find module defined in paths

I have a typescript application that has paths for absolute imports. My tsconfig looks like this: { “compilerOptions”: { “baseUrl”: “.”, “paths”: { “utils*”: [“src/utils*”], “operations*”: [“src/operations*”], “actions*”: [“src/actions*”], “components*”: [“src/components*”], “constants*”: [“src/constants*”], }, “outDir”: “dist”, “module”: “esnext”, “target”: “esnext”, “moduleResolution”: “node”, “noEmit”: true, “lib”: [“es2017”, “dom”], “noUnusedLocals”: true, “sourceMap”: true, “skipLibCheck”: true, “allowJs”: true, […]

Categories
Development

jest cannot resolve module aliases

I am using a npm module called module-alias. I map some modules in tsconfig.json and package.json tsconfig.json “compilerOptions”: { “baseUrl”: “./src”, “paths”: { “@config/*”: [“config/*”], “@interfaces/*”: [“interfaces/*”], “@services/*”: [“services/*”] }, “module”: “commonjs”, “target”: “es2015”, /* Specify module code generation: ‘none’, ‘commonjs’, ‘amd’, ‘system’, ‘umd’, ‘es2015’, or ‘ESNext’. */ “sourceMap”: true, “outDir”: “./dist”, /* Redirect output […]

Categories
Development

Starting nestjs in production mode

I am using akveo backend bundle that I bought, and while everything seems to be working fine in development mode starting in production gives me following errors, I am new to nestjs itself. Anyone know what’s going here? node_modules/@nestjs/core/adapters/http-adapter.d.ts:5:31 – error TS2420: Class ‘AbstractHttpAdapter<TServer, TRequest, TResponse>’ incorrectly implements interface ‘HttpServer<TRequest, TResponse>’. Property ‘status’ is missing […]

Categories
Development

Typescript project setup with shared package

I have a few premises before starting: I want a shared package which will be included in three other packages, typescript, just one node modules, multiplatform usage (Windows / Linux), use dependencies from the shared package, (live reload will be nice), not to lose the ability to later publish shared package (the other three packages […]