ionic-team/angular-toolkit

bug: generate component generates wrong test file

Yohandah opened this issue · 1 comments

The following line with @ionic/angular-toolkit 3.0 & Angular 11

angular.json

"cli": {
    "defaultCollection": "@ionic/angular-toolkit"
}

generates a wrong test file structure that is like that : (using deprecated async in Angular 11)

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';

import { MyComponent } from './my.component';

describe('MyComponent', () => {
  let component: MyComponent;
  let fixture: ComponentFixture<MyComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ MyComponent ],
      imports: [IonicModule.forRoot()]
    }).compileComponents();

    fixture = TestBed.createComponent(MyComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  }));

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

removing the line in angular.json and using Angular 11 CLI generates the correct following test file (using async/await) :

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

import { MyComponent } from './my.component';

describe('MyComponent', () => {
  let component: MyComponent;
  let fixture: ComponentFixture<MyComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [ MyComponent ]
    })
    .compileComponents();
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(MyComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

I also add that the .forRoot in imports isn't necessary and will throw warnings I always remove it in my tests files.

👍 Thanks for the heads up! If you're up for submitting a PR, that would be great!