Skip to content

@angular/core/testing has no exported member addProviders #2288

Closed

Description

@jeffarese

Please provide us with the following information:

  1. OS? Ubuntu 16.04 LTS
  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: 1.0.0-beta.15
node: 6.5.0
os: linux x64
  1. Repro steps. Was this an app that wasn't created using the CLI? What change did you
    do on your code? etc.

I created a new Class using the ng g class generator. In this case, it was a class called user, so I got a user.ts and user.spec.ts
The generated user.spec.ts had the following content:

/* tslint:disable:no-unused-variable */

import { addProviders, async, inject } from '@angular/core/testing';
import {User} from './user';

describe('User', () => {
  it('should create an instance', () => {
    expect(new User()).toBeTruthy();
  });
});

The addProviders give an error because it doesn't exist in @angular/core/testing

  1. The log given by the failure. Normally this include a stack trace and some
    more information.
ERROR in [default] [...]/src/app/core/user/user.spec.ts:3:9 
Module '"[...]/node_modules/@angular/core/testing/index"' has no exported member 'addProviders'.
  1. Mention any other details that might be useful.

Thanks! We'll be in touch soon.

Activity

  1. deebloo commented on Sep 22, 2016

    @deebloo
    Contributor

    AddProviders was deprecated. Use Testbed instead. Also this is angular specific not cli specific

  2. jeffarese commented on Sep 22, 2016

    @jeffarese
    Author

    @deebloo The thing is that the Angular CLI generates the test file with the AddProviders. I know they are deprecated, my issue was about stating the fact that Angular CLI shouldn't use AddProviders in the generated class.spec.ts

  3. deebloo commented on Sep 22, 2016

    @deebloo
    Contributor

    The newest version of the cli uses Testbed

  4. deebloo commented on Sep 22, 2016

    @deebloo
    Contributor

    That code looks like it is from an old version of the cli

  5. jeffarese commented on Sep 22, 2016

    @jeffarese
    Author

    My version of CLI is angular-cli: 1.0.0-beta.15.
    The CLI is using TestBed in most generators (component, service...etc) But not in the class generator. You can check it if you want.

  6. deebloo commented on Sep 22, 2016

    @deebloo
    Contributor

    @jeffarese nope you are totally correct. Looks like the class generator creates a bad test for class. (apologies I didn't see that you were generating class, thought it was service. Definitely a bug) Good catch

  7. jeffarese commented on Sep 22, 2016

    @jeffarese
    Author

    Yeah, I'm afraid it's a bug :( no apologies needed!

  8. deebloo commented on Sep 22, 2016

    @deebloo
    Contributor

    I just submitted a PR that removes those imports

  9. added a commit that references this issue on Oct 5, 2016
    9d4efb5
  10. added a commit that references this issue on Oct 14, 2016
    2026d3f
  11. added a commit that references this issue on Oct 19, 2016
    bf54320
  12. added a commit that references this issue on Nov 3, 2016
    a87897a
  13. 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.

  14. locked and limited conversation to collaborators on Sep 6, 2019
  15. added a commit that references this issue on May 29, 2026
    d69d43a
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