Skip to content

Commit

Permalink
fix: correct deprecation message of ngcc-jest-processor
Browse files Browse the repository at this point in the history
Closes #1411
  • Loading branch information
anh.pham committed Apr 24, 2022
1 parent 73f81ca commit 3899abf
Show file tree
Hide file tree
Showing 96 changed files with 2,743 additions and 3,420 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@ import { TestBed, waitForAsync } from '@angular/core/testing';
})
class BarComponent {}

test(
'templateUrl/styleUrls/styles should work',
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [BarComponent],
});
const fixture = TestBed.createComponent(BarComponent);
fixture.detectChanges();
test('templateUrl/styleUrls/styles should work', waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [BarComponent],
});
const fixture = TestBed.createComponent(BarComponent);
fixture.detectChanges();

const elementToFind = fixture.debugElement.nativeElement.querySelector('p');
expect(elementToFind).toBeDefined();
expect(window.getComputedStyle(elementToFind).color).toEqual('');
expect(window.getComputedStyle(elementToFind).fontSize).toEqual('');
}),
);
const elementToFind = fixture.debugElement.nativeElement.querySelector('p');
expect(elementToFind).toBeDefined();
expect(window.getComputedStyle(elementToFind).color).toEqual('');
expect(window.getComputedStyle(elementToFind).fontSize).toEqual('');
}));
17 changes: 7 additions & 10 deletions e2e/async/__tests__/async.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,11 @@ describe('async with Angular testing apis', () => {
expect(flag).toBe(true);
}));

test(
'waitForAsync should work',
waitForAsync(() => {
let flag = false;
setTimeout(() => {
flag = true;
expect(flag).toBe(true);
}, 100);
}),
);
test('waitForAsync should work', waitForAsync(() => {
let flag = false;
setTimeout(() => {
flag = true;
expect(flag).toBe(true);
}, 100);
}));
});
16 changes: 7 additions & 9 deletions e2e/full-ivy-lib/__tests__/full-ivy-lib.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ describe('Full Ivy library', () => {
let fullIvyComponent: FullIvyComponent;
let fullIvyService: FullIvyService;

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [FullIvyModule],
});
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [FullIvyModule],
});

fullIvyComponent = TestBed.createComponent(FullIvyComponent).componentInstance;
fullIvyService = TestBed.inject(FullIvyService);
}),
);
fullIvyComponent = TestBed.createComponent(FullIvyComponent).componentInstance;
fullIvyService = TestBed.inject(FullIvyService);
}));

test('should create the component instance', () => {
expect(fullIvyComponent).toBeDefined();
Expand Down
16 changes: 7 additions & 9 deletions e2e/partial-ivy-lib/__tests__/partial-ivy-lib.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ describe('Partial Ivy library', () => {
let partialIvyComponent: PartialIvyComponent;
let partialIvyService: PartialIvyService;

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [PartialIvyModule, PartialIvyTestingModule],
});
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [PartialIvyModule, PartialIvyTestingModule],
});

partialIvyComponent = TestBed.createComponent(PartialIvyComponent).componentInstance;
partialIvyService = TestBed.inject(PartialIvyService);
}),
);
partialIvyComponent = TestBed.createComponent(PartialIvyComponent).componentInstance;
partialIvyService = TestBed.inject(PartialIvyService);
}));

test('should create the component instance', () => {
expect(partialIvyComponent).toBeDefined();
Expand Down
21 changes: 9 additions & 12 deletions e2e/snapshot-serializers/__tests__/foo.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ class FooComponent {
condition2 = false;
}

test(
'snapshot should work',
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [FooComponent],
});
test('snapshot should work', waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [FooComponent],
});

const fixture = TestBed.createComponent(FooComponent);
fixture.detectChanges();
const fixture = TestBed.createComponent(FooComponent);
fixture.detectChanges();

expect(fixture).toMatchSnapshot();
expect(fixture.debugElement.nativeElement).toMatchSnapshot();
}),
);
expect(fixture).toMatchSnapshot();
expect(fixture.debugElement.nativeElement).toMatchSnapshot();
}));
53 changes: 21 additions & 32 deletions examples/example-app-v11/src/app/app-initial.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,27 @@ import { ComponentFixture } from '@angular/core/testing';
import { AppComponent } from './app-initial.component';

describe('AppComponent (initial CLI version)', () => {
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
}).compileComponents();
}),
);
it(
'should create the app',
waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
}),
);
it(
`should have as title 'app'`,
waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('app');
}),
);
it(
'should render title',
waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain('Welcome to app!');
}),
);
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
}).compileComponents();
}));
it('should create the app', waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
}));
it(`should have as title 'app'`, waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('app');
}));
it('should render title', waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain('Welcome to app!');
}));
});

describe('AppComponent (initial CLI version - as it should be)', () => {
Expand Down
14 changes: 6 additions & 8 deletions examples/example-app-v11/src/app/app.component.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ let router: Router;
let location: SpyLocation;

describe('AppComponent & RouterTestingModule', () => {
beforeEach(
waitForAsync(() => {
void TestBed.configureTestingModule({
imports: [AppModule, RouterTestingModule.withRoutes(routes)],
providers: [{ provide: HeroService, useClass: TestHeroService }],
}).compileComponents();
}),
);
beforeEach(waitForAsync(() => {
void TestBed.configureTestingModule({
imports: [AppModule, RouterTestingModule.withRoutes(routes)],
providers: [{ provide: HeroService, useClass: TestHeroService }],
}).compileComponents();
}));

it('should navigate to "Dashboard" immediately', fakeAsync(() => {
createComponent();
Expand Down
84 changes: 39 additions & 45 deletions examples/example-app-v11/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,59 +21,53 @@ let comp: AppComponent;
let fixture: ComponentFixture<AppComponent>;

describe('AppComponent & TestModule', () => {
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent,
RouterLinkDirectiveStub,
BannerStubComponent,
RouterOutletStubComponent,
WelcomeStubComponent,
],
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
});
}),
);
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent,
RouterLinkDirectiveStub,
BannerStubComponent,
RouterOutletStubComponent,
WelcomeStubComponent,
],
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
});
}));
tests();
});

describe('AppComponent & NO_ERRORS_SCHEMA', () => {
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [AppComponent, BannerStubComponent, RouterLinkDirectiveStub],
schemas: [NO_ERRORS_SCHEMA],
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
});
}),
);
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [AppComponent, BannerStubComponent, RouterLinkDirectiveStub],
schemas: [NO_ERRORS_SCHEMA],
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
});
}));
tests();
});

describe('AppComponent & AppModule', () => {
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({ imports: [AppModule] })
.overrideModule(AppModule, {
remove: { imports: [AppRoutingModule] },
add: { declarations: [RouterLinkDirectiveStub, RouterOutletStubComponent] },
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
});
}),
);
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ imports: [AppModule] })
.overrideModule(AppModule, {
remove: { imports: [AppRoutingModule] },
add: { declarations: [RouterLinkDirectiveStub, RouterOutletStubComponent] },
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
});
}));

tests();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ describe('BannerComponent (initial CLI generated)', () => {
let component: BannerComponent;
let fixture: ComponentFixture<BannerComponent>;

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({ declarations: [BannerComponent] }).compileComponents();
}),
);
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ declarations: [BannerComponent] }).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(BannerComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ describe('DashboardHeroComponent when tested directly', () => {
let heroDe: DebugElement;
let heroEl: HTMLElement;

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({ declarations: [DashboardHeroComponent] }).compileComponents();
}),
);
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ declarations: [DashboardHeroComponent] }).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DashboardHeroComponent);
Expand Down Expand Up @@ -92,11 +90,9 @@ describe('DashboardHeroComponent when inside a test host', () => {
let fixture: ComponentFixture<TestHostComponent>;
let heroEl: HTMLElement;

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({ declarations: [DashboardHeroComponent, TestHostComponent] }).compileComponents();
}),
);
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ declarations: [DashboardHeroComponent, TestHostComponent] }).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(TestHostComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ describe('DashboardComponent class only', () => {
expect(comp.heroes.length).toEqual(0);
});

it(
'should HAVE heroes after HeroService gets them',
waitForAsync(() => {
comp.ngOnInit();
heroService.lastHeroesResult?.subscribe(() => {
expect(comp.heroes.length).toBeGreaterThan(0);
});
}),
);
it('should HAVE heroes after HeroService gets them', waitForAsync(() => {
comp.ngOnInit();
heroService.lastHeroesResult?.subscribe(() => {
expect(comp.heroes.length).toBeGreaterThan(0);
});
}));

it('should tell ROUTER to navigate by hero id', () => {
const hero: Hero = { id: 42, name: 'Abbracadabra' };
Expand Down
Loading

0 comments on commit 3899abf

Please sign in to comment.