Angular-cli: ng test not working on updated sources

Created on 26 Feb 2017  路  13Comments  路  Source: angular/angular-cli

Please provide us with the following information:

OS?

Windows 10 x64

Versions.

RC.0

Repro steps.

Added more complicated tests and while 'ng test' is watching, I change some code, and it doesn't really get the updated code. So the new test iteration works on previous code (unchanged). Also, I get weird errors after the code changed:

ERROR in [path]/services/myservice.service.spec.ts (24,1): Cannot find name 'describe'.)
[path]/services/myservice.service.spec.ts (45,9): Type 'undefined' is not assignable to type 'string'.)
[path]/services/myservice.service.spec.ts (48,5): Cannot find name 'beforeEach'.)
[path]/services/myservice.service.spec.ts (61,5): Cannot find name 'beforeEach'.)
[path]/services/myservice.service.spec.ts (65,27): Cannot find name 'jasmine'.)
[path]/services/myservice.service.spec.ts (66,9): Cannot find name 'jasmine'.)

So now I have to restart 'ng test' every time I change the code :( This is actually a blocker.

Most helpful comment

Do you have "dom" included in your "lib" array in src\tsconfig.spec.json? Does adding it help?

All 13 comments

Do you have "dom" included in your "lib" array in src\tsconfig.spec.json? Does adding it help?

I have the same error with Angular 4, I have copied the tsconfig files from a new project.

ng -v
```@angular/cli: 1.0.0-rc.0
node: 6.9.1
os: win32 x64
@angular/common: 4.0.0-rc.1
@angular/compiler: 4.0.0-rc.1
@angular/core: 4.0.0-rc.1
@angular/forms: 4.0.0-rc.1
@angular/http: 4.0.0-rc.1
@angular/platform-browser: 4.0.0-rc.1
@angular/platform-browser-dynamic: 4.0.0-rc.1
@angular/router: 4.0.0-rc.1
@angular/cli: 1.0.0-rc.0
@angular/compiler-cli: 4.0.0-rc.1

tsconfig.json

{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2016"
]
}
}

tsconfig.spec.json

{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"module": "commonjs",
"target": "es6",
"baseUrl": "",
"types": [
"jasmine",
"node"
]
},
"files": [
"test.ts"
],
"include": [
"*/.spec.ts"
]
}


ERROR in .../src/app/main/admin/partners/details/details.resolve.spec.ts (15,1): Cannot find name 'describe'.)
.../src/app/main/admin/partners/details/details.resolve.spec.ts (45,3): Cannot find name 'beforeEach'.)
.../src/app/main/admin/partners/details/details.resolve.spec.ts (74,3): Cannot find name 'it'.)
.../src/app/main/admin/partners/details/details.resolve.spec.ts (77,5): Cannot find name 'expect'.)
.../src/app/main/admin/partners/details/details.resolve.spec.ts (78,5): Cannot find name 'expect'.)
.../src/app/main/admin/partners/details/details.resolve.spec.ts (79,5): Cannot find name 'expect'.)
.../src/app/main/admin/partners/details/details.resolve.spec.ts (82,3): Cannot find name 'it'.)
.../src/app/main/admin/partners/details/details.resolve.spec.ts (85,5): Cannot find name 'expect'.)
.../src/app/main/admin/partners/details/details.resolve.spec.ts (86,5): Cannot find name 'expect'.)
.../src/app/main/admin/partners/details/details.resolve.spec.ts (87,5): Cannot find name 'expect'.)
```

@anderaus why? I got all files from 'ng new'. why should I add more to test my project?

@anderaus this doesn't seem to help. I'm getting this issue since upgrading to rc0.

For the record, this is only happening when using the --ng4 flag in rc0. I've tried it without the flag and everything seems to be working as expected.

I don't use any flags, and it happens to me. Angular 2.4.8.

Angular CLI RC0 generates a package.json file with the TypeScript version set to ~2.0.0. Have you changed this? It appears to be OK to update other package versions but if you update TypeScript (to 2.1 or 2.2) it'll break the test environment, manifesting just the behaviour you describe.

OK, that did the trick. Thanks to @stuarthallows comment about TypeScript update to 2.2. I returned to 2.0.10 and everything works as expected.

Steps to reproduce this just with the hello-world app (@angular/[email protected] in Windows 10):

  1. ng new test-ng2 , ng test, while running, change a test and break it. I will work as expected. Using typescript 2.0.10

  2. ng new test-ng4 --ng4 , ng test, while running, change a test and break it. I will show some errors about not finding describe, it... and then the result will be the first one. Using typescript 2.0.10 doesn't work. I tried with 2.1.6 and even 2.2.1. Still the same issue...

Also getting this issue on a new and upgraded project, it makes unit testing incredibly slow. Windows 10 and RC.1 on ng4

The new tsconfig files with @angular/[email protected] seems to solve the problem for me. I had to fix zone.js on 0.8.0, because 0.8.1 caused typeerrors in my tests.

ng -v

node: 6.10.0
os: win32 x64
@angular/common: 4.0.0-rc.3
@angular/compiler: 4.0.0-rc.3
@angular/core: 4.0.0-rc.3
@angular/forms: 4.0.0-rc.3
@angular/http: 4.0.0-rc.3
@angular/platform-browser: 4.0.0-rc.3
@angular/platform-browser-dynamic: 4.0.0-rc.3
@angular/router: 4.0.0-rc.3
@angular/cli: 1.0.0-rc.2
@angular/compiler-cli: 4.0.0-rc.3

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

tsconfig.spec.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "module": "commonjs",
    "target": "es5",
    "baseUrl": "",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "test.ts"
  ],
  "include": [
    "**/*.spec.ts"
  ]
}

Seems to have been a bad update. This should help https://github.com/angular/angular-cli/wiki/stories-rc-update.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings