11import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2+ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' ;
23import { RouterTestingModule } from '@angular/router/testing' ;
34import { AppComponent } from './app.component' ;
5+ import { MatToolbarModule } from '@angular/material/toolbar' ;
6+ import { MatIconModule } from '@angular/material/icon' ;
7+ import { MatSidenavModule } from '@angular/material/sidenav' ;
8+ import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
9+ import { of } from 'rxjs' ;
10+ import { ThemeService } from './service/theme.service' ;
11+ import { TitleService } from './service/title.service' ;
12+
13+ class MockThemeService {
14+ initTheme ( ) { }
15+ }
16+
17+ class MockTitleService {
18+ titleInfo$ = of ( {
19+ dimension : 'Test Title' ,
20+ level : '1' ,
21+ } ) ;
22+ }
423
524describe ( 'AppComponent' , ( ) => {
625 let app : AppComponent ;
726 let fixture : ComponentFixture < AppComponent > ;
827
928 beforeEach ( async ( ) => {
1029 await TestBed . configureTestingModule ( {
11- imports : [ RouterTestingModule ] ,
1230 declarations : [ AppComponent ] ,
31+ imports : [
32+ RouterTestingModule ,
33+ MatToolbarModule ,
34+ MatIconModule ,
35+ MatSidenavModule ,
36+ BrowserAnimationsModule ,
37+ ] ,
38+ providers : [
39+ { provide : ThemeService , useClass : MockThemeService } ,
40+ { provide : TitleService , useClass : MockTitleService } ,
41+ ] ,
42+ schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
1343 } ) . compileComponents ( ) ;
1444 } ) ;
1545
@@ -24,10 +54,9 @@ describe('AppComponent', () => {
2454 } ) ;
2555
2656 it ( 'check for fork me on github ribbon generation' , ( ) => {
27- const fixture = TestBed . createComponent ( AppComponent ) ;
28- const HTMLElement : HTMLElement = fixture . nativeElement ;
29- var divTag = HTMLElement . querySelector ( 'div' ) ! ;
30- var aTag = divTag . querySelector ( 'a' ) ! ;
31- expect ( aTag . textContent ) . toContain ( 'GitHub' ) ;
57+ const compiled = fixture . nativeElement as HTMLElement ;
58+ const githubLink = compiled . querySelector ( '.github-fork-ribbon' ) ;
59+ expect ( githubLink ) . not . toBeNull ( ) ;
60+ expect ( githubLink ?. textContent ?. trim ( ) ) . toBe ( 'Fork me on GitHub' ) ;
3261 } ) ;
3362} ) ;
0 commit comments