You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ng test / Karma fails with errors in browser: "Refused to execute script .. .test.ts" #2031
OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
Windows 10
Versions. Please run ng --version. If there's nothing outputted, please run
in a Terminal: node --version and paste the result here:
angular-cli: local (v1.0.0-beta.11-webpack.8, branch: master)
node: 6.5.0
os: win32 x64
Repro steps. Was this an app that wasn't created using the CLI? What change did you
do on your code? etc.
Create new app: ng new newapp
try and run tests: ng test
The log given by the failure. Normally this include a stack trace and some
more information.
ERROR in [default] C:\code\a2cli\src\app\app.component.spec.ts:3:9
Module '"C:/code/a2cli/node_modules/@angular/core/testing/index"' has no exported member 'addProviders'.
ERROR in [default] C:\code\a2cli\src\app\nav-bar\nav-bar.component.spec.ts:5:9
Module '"C:/code/a2cli/node_modules/@angular/core/testing/index"' has no exported member 'addProviders'.
Ok, I was able to figure out how to fix(?) the errors.
In the app.component.spec.ts files, I changed the import from: import { addProviders, async, inject } from '@angular/core/testing';
to: import { TestBed, async, inject } from '@angular/core/testing';
and the code in the beforeEach() method to: TestBed.configureTestingModule([AppComponent]);
Those errors are gone, but doing ng test just brings up an empty browser window (with a Karma heading). There is, however an error in the console:
Refused to execute script from 'http://localhost:9876/base/src/test.ts?a6b943b4e0874f5ac9e782c850ebf91d7a8babf4' because its MIME type ('video/mp2t') is not executable.
changed the title [-]ng test command fails with errors [/-][+]ng test / Karma fails with errors in browser: "Refused to execute script .. .test.ts"[/+]on Sep 14, 2016
Also, warnings are generated for internal Angular code:
WARNING in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
45:15 Critical dependency: the request of a dependency is an expression
WARNING in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
57:15 Critical dependency: the request of a dependency is an expression
Activity
jtsom commentedon Sep 9, 2016
Ok, I was able to figure out how to fix(?) the errors.
In the app.component.spec.ts files, I changed the import from:
import { addProviders, async, inject } from '@angular/core/testing';to:
import { TestBed, async, inject } from '@angular/core/testing';and the code in the beforeEach() method to:
TestBed.configureTestingModule([AppComponent]);Those errors are gone, but doing ng test just brings up an empty browser window (with a Karma heading). There is, however an error in the console:
jtsom commentedon Sep 14, 2016
Any info on this latest problem? Can't run Karma tests because of it, making testing useless...
[-]ng test command fails with errors [/-][+]ng test / Karma fails with errors in browser: "Refused to execute script .. .test.ts"[/+]jtsom commentedon Sep 14, 2016
Also, warnings are generated for internal Angular code:
filipesilva commentedon Sep 21, 2016
Closing in favor of #2125 because that one has more information.
angular-automatic-lock-bot commentedon Sep 6, 2019
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.