Skip to content

refactor(@schematics/angular): inject the service at setup #15438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2019

Conversation

kasaharu
Copy link
Contributor

Suggestion

  • I want to inject a service at setup at CLI-generated service spec file.

Why

beforeEach(() => {
  TestBed.configureTestingModule({ providers: [ValueService] });
  service = TestBed.get(ValueService);
});

Version

  • Angular CLI : 8.3.0

Generated code

current

import { TestBed } from '@angular/core/testing';

import { HeroService } from './hero.service';

describe('HeroService', () => {
  beforeEach(() => TestBed.configureTestingModule({}));

  it('should be created', () => {
    const service: HeroService = TestBed.get(HeroService);
    expect(service).toBeTruthy();
  });
});

suggestion

import { TestBed } from '@angular/core/testing';

import { HeroService } from './hero.service';

describe('HeroService', () => {
  let service: HeroService;

  beforeEach(() => {
    TestBed.configureTestingModule({});
    service = TestBed.get(HeroService);
  });

  it('should be created', () => {
    expect(service).toBeTruthy();
  });
});

@clydin
Copy link
Member

clydin commented Aug 26, 2019

Looks good but can you adjust the commit message to be more descriptive?
Maybe something similar to refactor(@schematics/angular): use beforeEach to get service in service unit test

@clydin clydin added the target: major This PR is targeted for the next major release label Aug 26, 2019
@kasaharu kasaharu force-pushed the inject-service-at-setup branch from 71fcf97 to 4923c72 Compare August 26, 2019 15:31
@kasaharu
Copy link
Contributor Author

Thank you for your check 😄
I adjusted this commit message.

@mgechev mgechev merged commit 66280bc into angular:master Aug 26, 2019
@kasaharu kasaharu deleted the inject-service-at-setup branch August 27, 2019 07:14
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants