Skip to content

ng test / Karma fails with errors in browser: "Refused to execute script .. .test.ts" #2031

Closed

Description

@jtsom

Please provide us with the following information:

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
    Windows 10
  2. 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
  1. 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

  1. 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'.
  1. Mention any other details that might be useful.

Tests cannot be run.


Thanks! We'll be in touch soon.

Activity

  1. jtsom commented on Sep 9, 2016

    @jtsom
    ContributorAuthor

    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.
    
  2. jtsom commented on Sep 14, 2016

    @jtsom
    ContributorAuthor

    Any info on this latest problem? Can't run Karma tests because of it, making testing useless...

  3. 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
  4. jtsom commented on Sep 14, 2016

    @jtsom
    ContributorAuthor

    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     
    
  5. filipesilva commented on Sep 21, 2016

    @filipesilva
    Contributor

    Closing in favor of #2125 because that one has more information.

  6. angular-automatic-lock-bot commented on Sep 6, 2019

    @angular-automatic-lock-bot

    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.

  7. locked and limited conversation to collaborators on Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions