Pompey Magnus
Pompey Magnus

Reputation: 2341

Angular 2 Karma tests have started to fail can't capture browser

This seems like a project setup problem in someway. This was working previously. I don't have the knowledge that these error messages help me to start. Does anyone have some advice on where to start diagnosing the problem?

21 05 2017 07:42:55.094:WARN [karma]: No captured browser, open http://localhost:9876/
21 05 2017 07:42:55.110:INFO [karma]: Karma v1.4.1 server started at http://0.0.0.0:9876/
21 05 2017 07:42:55.110:INFO [launcher]: Launching browser Chrome with unlimited concurrency
21 05 2017 07:42:55.118:INFO [launcher]: Starting browser Chrome                                                                                                                                                                                                        ERROR in /Users/jgreenaw/WebstormProjects/legalcoveapp/node_modules/@angular/core/src/testability/testability.d.ts (41,33): Cannot find name 'Node'.

ERROR in /Users/jgreenaw/WebstormProjects/legalcoveapp/node_modules/@angular/forms/src/directives/ng_form.d.ts (69,22): Cannot find name 'Event'.

ERROR in /Users/jgreenaw/WebstormProjects/legalcoveapp/node_modules/@angular/forms/src/directives/reactive_directives/form_group_directive.d.ts (74,22): Cannot find name 'Event'.

ERROR in /Users/jgreenaw/WebstormProjects/legalcoveapp/node_modules/@ng-bootstrap/ng-bootstrap/rating/rating.d.ts (58,26): Cannot find name 'KeyboardEvent'.

ERROR in /Users/jgreenaw/WebstormProjects/legalcoveapp/node_modules/@ng-bootstrap/ng-bootstrap/typeahead/typeahead.d.ts (81,26): Cannot find name 'KeyboardEvent'.

Upvotes: 4

Views: 1200

Answers (3)

Ian
Ian

Reputation: 3149

If running karma test from your IDE (for example, IntelliJ IDEA) and your solution doesn't build/has lint errors, karma seems to not connect and just hang.

Run your tests with something like ng test and get that working before running from your IDE.

Upvotes: 0

Heather92065
Heather92065

Reputation: 7893

After upgrading my Angular lib versions, my Karma tests too started to fail which led me to the this question. After verifying the @angular/cli versions, now 1.1.2, match between global and the local project the following may also be required:

Update your src/tsconfig.spec.json by adding "dom" to the lib array:

"lib": ["es2016", "dom"],

Upvotes: 5

Pompey Magnus
Pompey Magnus

Reputation: 2341

I was able to move forward past the problem, but not identify the root cause by doing the following.

  • sync angular/cli project and global versions to latest: 1.0.4
  • rm node_modules which I had done before, but reading this. I was missing npm cache clean
  • npm install

Thanks @MatthewDaly for the useful suggestions and questions.

Upvotes: 0

Related Questions