This is a minimal reproduction for an issue in JetBrains IDEs. TL;DR: IDE thinks unit tests are Chai/Mocha tests but they're Jasmine ones. Probably because confusing them with Cypress tests instead. Therefore unit test assertions (i.e.: toBeTruthy) appear in red color as the definitions aren't found. Though they actually work (like when running them with ng test)
After reply from a JetBrains team member, the suggested fix is to refer to tsconfig.app/spec.json from tsconfig.json
This has been applied in commit 24f929b
After that, when using WebStorm 2024.2.3 seems the issue about assertion types is fixed.
Though the docs / "Go to declaration" of beforeEach, describe, it and expect are wrong.
When using Cmd + B and F1 to see docs, Mocha/Chai docs appear:
Mocha ones appear for beforeEach, describe and it. Chai ones for expect.
When using "Go to declaration or usages" you go to (chai|mocha)/index.d.ts
To create the repository, a fresh Angular app has been created with the following command:
pnpm dlx @angular/cli new \
--package-manager=pnpm \
angular-18-cypress-jasmine-typesChoosing defaults: CSS + no SSR/SSG. Using pnpm for performance purposes.
The issue isn't be there when cloning the repo. However, switch into one of the two branches:
root-schematic. Where Cypress has been added via Cypress Angular Schematicroot-manual. Where Cypress has been added manually bypnpm install -DE cypress
For instance, git checkout root-manual. Then run pnpm install. Open the example unit test file app.component.spec.ts. The issue appears. toBeTruthy appears in red color. Amongst the rest of assertions too.
When switching back to main branch to write this note in README.md the issue disappeared. Switching to a branch where Cypress has been added, raises the issue back again.
Notice some time must pass for the red color to appear. What is instant is that hovering over toBeTruthy or other assertions triggers a popup saying that there are no definitions available. When if in main branch where no Cypress exists, hovering over the assertion triggers a popup with Jasmine's documentation
Turned off Test Automation plugin just in case. Restored default settings just incase. Invalidated caches too.
Now
Test Automationplugin is reporting an issue about OpenAPI when enabling it back. Will create a separate issue for that too.
This project was generated with Angular CLI version 18.2.5.
Run ng serve for a dev server. Navigate to http://localhost:4200/. The application will automatically reload if you change any of the source files.
Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.
Run ng build to build the project. The build artifacts will be stored in the dist/ directory.
Run ng test to execute the unit tests via Karma.
Run ng e2e to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
To get more help on the Angular CLI use ng help or go check out the Angular CLI Overview and Command Reference page.
