Angular Unit Tests Property 'toBeTruthy' does not exist on type 'Assertion'
Asked Answered
M

3

11

Currently in a project Ive been assigned to there is an issue with VSCode not being able to determine the properties for the Jasmine assertions. The tests run successfully, but intellisense in VSCode cannot determine the package. This project has cypress configured along side jasmine, but I dont see any conflicts in the tsconfig.spec.json. enter image description here

enter image description here

Military answered 16/12, 2022 at 16:58 Comment(2)
Please give a minimal reproducible example, as text.Hannie
Hi there. What is your Cypress version? I faced a similar issue and installed a previous Cypress version using ng add @cypress/[email protected] and then added ./cypress.config.ts to the tsconfig.exclude property like so: "exclude": ["./cypress.config.ts"] Here is the cypress issue on Github: github.com/cypress-io/cypress/issues/…Digitate
M
13

I was able to follow @aghwotu recommendation and added the below to my tsconfig.json in my root. This created other issues, but fixed my issue with VSCode not finding the jasmine Assertions.

"exclude": ["cypress.config.ts"],
"files": ["cypress.config.ts"]
Military answered 20/12, 2022 at 19:59 Comment(3)
What "other issues"?Disputant
In a more complex project, you might need to also exclude cypress packages like badeball as well. So this is just a general answer to what can be a further problem down the road with the more cypress packages that are installed.Military
Cause "Cannot find module '@angular/router/testing'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?" in angular spec, @Rdev is better for angular env (tested on angular 18+ and cypress 13+) .Hereditary
B
11

I encountered the same problem today. I know the problem is already a year old, but perhaps the answer will help someone else who also runs into this.

I added the following to my tsconfig.json:

  "exclude": [
    "cypress/**/*.ts",
    "cypress.config.ts"
  ]

And I changed my cypress/tsconfig.json, which extends the tsconfig.json, to:

  "include": [
    "**/*.ts",
    "../cypress.config.ts"
  ],
  "exclude": []

This solved my issues with types and functions not being recognized in my .spec files and also kept my Cypress e2e tests running.

I hope this still helps you or someone else.

Blintze answered 29/12, 2023 at 8:41 Comment(0)
A
0

If the above do not work for you, creating a “Solution Style” tsconfig.json file worked for me.

Acrid answered 2/5 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.