I'm facing an issue with my Angular project's typescript configuration that is preventing the expect matchers from functioning properly

There seems to be a problem with the TypeScript configuration in my Angular project causing issues with expect matchers. Interestingly, when I remove the Cypress folder from the project, the expect matchers work perfectly fine along with IntelliSense. It appears that the presence of Cypress is triggering this issue.

I believe my configuration is pretty standard. I utilize cypress-schematic to set up the integration of Cypress with my Angular 14 project.

The errors are visible in my Karma/Jasmine *.spec.ts files. Here's a screenshot of what I'm encountering:

https://i.sstatic.net/Vxtu2.png

This is my tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "strict": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    ...
}

Here is my tsconfig.spec.json:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./dist/out-tsc/spec",
    "types": [
      "jasmine",
      "jasmine-expect",
      ...
    ]
  },
  ...
}

And here is my Cypress cypress/tsconfig.json:

{
  "extends": "../tsconfig.json",
  "include": ["**/*.ts"],
  "compilerOptions": {
    "sourceMap": false,
    ...
    ]
  }
}

Finally, this is my karma.config:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    files: [
      'node_modules/jasmine-expect/dist/jasmine-matchers.js'
    ],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      ...
    ],
    ....

Answer №1

It might be a good idea to exclude the cypress configurations from tsconfig.spec.json as it appears to be geared towards Karma tests.

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./dist/out-tsc/spec",
    "types": [
      "jasmine",
      "jasmine-expect",
    ]
  },
  "include": [
    "src/**/*.spec.ts",
    "src/**/*.d.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

Also, make sure to check the settings in cypress/tsconfig.json.

{
  "extends": "../tsconfig.json",
  "include": ["**/*.ts"],
  "compilerOptions": {
    "sourceMap": false,
    "types": ["cypress"]
  },
  "types": [
    "cypress"
  ]
}

If you are running Cypress component tests located under src/**/*.spec.ts, you may encounter some issues with the current setup.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to strip out a changing segment of text from a string?

let: string str = "a=<random text> a=pattern:<random text (may be fixed length)> a=<random text>"; In the given string above, let's assume that a= and pattern are constants. It is possible that there may or may not be a ...

The absence of a type in AnyAction is causing a TypeScript error in react testing

I ran into an issue and received the following error message: TS2345: Argument of type '(dispatch: Dispatch) => Promise<void>' is not assignable to parameter of type 'AnyAction'. Property 'type' is missing in type & ...

Discover the best way to cycle through bootsrap modal dialogs using angular

Within my component.ts file, there exists an array: dummyData = ['1', '2', '3']; The objective is to iterate through this array and generate 3 modals displaying values 1, 2, and 3 respectively. Here's a snippet of the ...

What are some ways I can implement timers and promises from Node 16 into a Typescript application?

The recent Node 16 release introduces a new timers/promises API that has caught my interest. I successfully installed Node 16 using NVM and switched to it: $ nvm use Found '/Users/golergka/Projects/my-project/.nvmrc' with version <16> ...

Angular 8: ngx-socket-io changes the connection URL while in production mode

One issue arises when running the application in production mode. In development mode, the socket client successfully connects to http://localhost:3002/socket.io/?EIO=3&transport=polling&t=N4--_Ms. However, in production mode, the URL changes to ht ...

Unable to run 'ng serve -o', however 'ng serve' functions correctly

Encountering an issue with Angular when attempting to configure the Micro frontend Framework (module federation) for both the remote and host applications. They are not located in the same workspace. When running the remote app with "ng serve -o", an error ...

Unable to create a loop within the constructor to assign API values

I created an export type shown below: export type Program{ key: string; value: string; } An array of values is returned from the API like this: apival = ["abc", "xyz" ...etc] In my component's constructor, I am implementing the f ...

Confusing generic function overload in TypeScript

During my exploration of TypeScript, I came across an unusual situation. function concat5<T>(strs: T, strs2: T): T; function concat5(strs: string, strs2: string) { return strs + strs2; } concat5(123, 12); concat5({a:1}, {b:2}); Upon reviewing ...

Issue encountered with combineLatest following upgrade of rxjs from version 6.x to 7.x

Upon upgrading rxjs from version 6.6.6 to 7.4.0, an error surfaced in my combineLatest function. searchQuery = new FormControl(null); searchStatus = new FormControl<UserStatus>('ALL'); searchParams$ = combineLatest( this.searchQuery.valu ...

Error in typing on a prismic application utilizing a ContentRelationshipField

I am facing a type error in my Prismic Next.js application that I am struggling to resolve. While the app functions properly, I keep encountering type errors like the following: The property 'data' does not exist on the type 'ContentRelati ...

Tips for enabling Azure Blob Storage file uploads in a React app while staying compliant with Content Security Policies

I am using an Azure Storage Account and a container to upload files from my React application. Through an Azure Function, I receive SAS Keys with the necessary permissions for file uploading. My CORS settings in the storage account allow all connections. ...

Determine the data type of the second element in a tuple by referencing the first element using dot notation

Background In my current project, I'm attempting to create a secure array of path segments for navigating through an object. The interface I'm developing is specifically designed to handle objects with only two levels of depth. Eventually, these ...

Guide on displaying a tooltip for an object in an Angular component using Bootstrap syntax

i have a data object structured like this var obj = {"test price type ty dynamic ": 10, test: 7, pricetype1u: 0, Price type 3: 0, Price type 2: 0} in my Angular component HTML, with Bootstrap styles applied, I've written the following code ...

Error: The specified property is not found in type 'never' - occurring with the ngFor loop variable

When working with API responses and dynamically sorting my view, I utilize an ngFor loop. Here's the snippet of code in question: <agm-marker *ngFor="let httpResponses of response" [latitude]= "httpResponses.lat" [longitude]=& ...

Connecting the SignalR client to various servers

I am currently incorporating SignalR version 2.x into my ASP.Net MVC application, which is also using the same version of SignalR in my Angular client app. The ASP.Net MVC application is hosted at http://localhost:42080, while the Angular app is hosted at ...

Typescript, React, and Express all in one: The error "ENOENT: no such file or directory, trying to access '/app/frontend/build/index.html'" has occurred

I recently set up an Express server in TypeScript, and here is the converted JavaScript code: class App { constructor() { this.app = express(); ... this.config(); ... } config() { if (process.env.NODE_EN ...

A function in Typescript is created to handle diverse input types in a generic manner

My goal is to create a function that can handle various input types for abstraction purposes. type ContentA = string type ContentB = number type InputA = { name: 'method_a' content: ContentA } type InputB = { name: 'method_b' con ...

Contrasting router and router-deprecated in angular2

After upgrading from version "beta.17" to "2.0.0-rc.1", I am a bit confused about when to use router and when to use router-deprecated. Can someone help clarify this for me? ...

Adjacent components

I have a query regarding the utilization of Angular. I aim to align the sentences side by side. These are two distinct components that I developed. I wish for recipe-list and recipes-details to function properly, with both statements displayed alongside ...

Is it advisable to send an http request within the ngOnInit of an Angular Universal component?

During my Angular app development, I did not encounter any errors while running it via ng serve. However, when I switched to SSR (Server-Side Rendering), I started receiving an error in my server log whenever a component that makes an http request as part ...