Angular-CLI with Jasmine unit tests, Chai types conflict
See original GitHub issueCurrent behavior:
Using Cypress with Typescript in Angular application causes type conflict between Mocha/Chai and Jasmine.
Angular-CLI project uses Jasmine for unit test, but Visual Studio Code intellisense can’t recognize Jasmine types, e.g. Property 'toBeTruthy' does not exist on type 'Assertion'.
.
I’ve tried every solution I’ve found but none works. Please investigate and provide the solution, don’t close this as a duplicate, as I am aware I am not first with this problem, but no solutions work.
Desired behavior:
Typescript support for both jasmine spec.ts files and Cypress spec.ts files.
Test code to reproduce
Using latest Visual Studio Code:
npm i -g @angular/cli
ng new ng-minimal-repo
cd ng-minimal-repo
npm i --save-dev cypress
./node_modules/.bin/cypress open
(to generate example spec files)
after renaming any of the Cypress spec files to .ts
file extension and opening the file in VSC, Jasmine unit test spec.ts files use Mocha/Chai types instead of Jasmine types.
Minimal reproduction app
I have also created minimal app where this problem occurs, no need to build, only clone and install:
git clone https://github.com/matusbielik/ng-cypress-types-problem
cd ng-cypress-types-problem
npm i
- then open
./ng-cypress-types-problem/cypress/integration/main.spec.ts
in Visual Studio Code.
After this, errors in ./ng-cypress-types-problem/src/app/app.component.spec.ts
should be highlighted.
Versions
Visual Studio Code: 1.45.1 AngularCLI: 9.1.7 OS: Ubuntu 18.04 Cypress: 4.7.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:30
- Comments:18
Top GitHub Comments
Hi @matusbielik
I had a similar issue. looks like is just a VS code thing as unit tests and e2e are still executing OK.
This is what solved my problem: https://github.com/cypress-io/cypress/issues/1087#issuecomment-552951441.
modify the main
tsconfig.json
file. (needs to betsconfig.json
, nottsconfig.spec.json
ortsconfig.app.json
)Look slike VS code is reading only
tsconfig.json
and nottsconfig.spec.json
, also only previously included files can be excludedIf your cypress tests are in a specific folder outside your src folder, you can juste exclude them in your tsconfig.json file
and all will work as expected