2017-10-27 22:48:50 +00:00
|
|
|
// #docplaster
|
|
|
|
|
// #docregion
|
2020-07-31 19:43:18 +00:00
|
|
|
import { TestBed, waitForAsync } from '@angular/core/testing';
|
2017-10-27 22:48:50 +00:00
|
|
|
// #enddocregion
|
|
|
|
|
import { AppComponent } from './app-initial.component';
|
|
|
|
|
/*
|
|
|
|
|
// #docregion
|
|
|
|
|
import { AppComponent } from './app.component';
|
|
|
|
|
|
|
|
|
|
describe('AppComponent', () => {
|
|
|
|
|
// #enddocregion
|
|
|
|
|
*/
|
|
|
|
|
describe('AppComponent (initial CLI version)', () => {
|
|
|
|
|
// #docregion
|
2020-07-31 19:43:18 +00:00
|
|
|
beforeEach(waitForAsync(() => {
|
|
|
|
|
TestBed
|
|
|
|
|
.configureTestingModule({
|
|
|
|
|
declarations: [AppComponent],
|
|
|
|
|
})
|
|
|
|
|
.compileComponents();
|
2017-10-27 22:48:50 +00:00
|
|
|
}));
|
2020-07-31 19:43:18 +00:00
|
|
|
it('should create the app', waitForAsync(() => {
|
|
|
|
|
const fixture = TestBed.createComponent(AppComponent);
|
|
|
|
|
const app = fixture.componentInstance;
|
|
|
|
|
expect(app).toBeTruthy();
|
|
|
|
|
}));
|
2021-12-05 10:36:03 +00:00
|
|
|
it("should have as title 'app'", waitForAsync(() => {
|
2020-07-31 19:43:18 +00:00
|
|
|
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();
|
2021-07-24 09:03:46 +00:00
|
|
|
const compiled = fixture.nativeElement as HTMLElement;
|
|
|
|
|
expect(compiled.querySelector('h1')?.textContent).toContain('Welcome to app!');
|
2020-07-31 19:43:18 +00:00
|
|
|
}));
|
2017-10-27 22:48:50 +00:00
|
|
|
});
|
|
|
|
|
// #enddocregion
|
|
|
|
|
|
|
|
|
|
/// As it should be
|
|
|
|
|
import { DebugElement } from '@angular/core';
|
|
|
|
|
import { ComponentFixture } from '@angular/core/testing';
|
|
|
|
|
|
|
|
|
|
describe('AppComponent (initial CLI version - as it should be)', () => {
|
|
|
|
|
let app: AppComponent;
|
|
|
|
|
let de: DebugElement;
|
|
|
|
|
let fixture: ComponentFixture<AppComponent>;
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
TestBed.configureTestingModule({
|
2020-07-31 19:43:18 +00:00
|
|
|
declarations: [AppComponent],
|
2017-10-27 22:48:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
fixture = TestBed.createComponent(AppComponent);
|
|
|
|
|
app = fixture.componentInstance;
|
|
|
|
|
de = fixture.debugElement;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should create the app', () => {
|
|
|
|
|
expect(app).toBeDefined();
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-05 10:36:03 +00:00
|
|
|
it("should have as title 'app'", () => {
|
2017-10-27 22:48:50 +00:00
|
|
|
expect(app.title).toEqual('app');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should render title in an h1 tag', () => {
|
|
|
|
|
fixture.detectChanges();
|
2020-07-31 19:43:18 +00:00
|
|
|
expect(de.nativeElement.querySelector('h1').textContent).toContain('Welcome to app!');
|
2017-10-27 22:48:50 +00:00
|
|
|
});
|
|
|
|
|
});
|