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' , ( ) => {
25+
626 let app : AppComponent ;
727 let fixture : ComponentFixture < AppComponent > ;
828
929 beforeEach ( async ( ) => {
1030 await TestBed . configureTestingModule ( {
11- imports : [ RouterTestingModule ] ,
1231 declarations : [ AppComponent ] ,
32+ imports : [
33+ RouterTestingModule ,
34+ MatToolbarModule ,
35+ MatIconModule ,
36+ MatSidenavModule ,
37+ BrowserAnimationsModule
38+ ] ,
39+ providers : [
40+ { provide : ThemeService , useClass : MockThemeService } ,
41+ { provide : TitleService , useClass : MockTitleService }
42+ ] ,
43+ schemas : [ CUSTOM_ELEMENTS_SCHEMA ]
1344 } ) . compileComponents ( ) ;
1445 } ) ;
1546
@@ -24,10 +55,9 @@ describe('AppComponent', () => {
2455 } ) ;
2556
2657 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' ) ;
58+ const compiled = fixture . nativeElement as HTMLElement ;
59+ const githubLink = compiled . querySelector ( '.github-fork-ribbon' ) ;
60+ expect ( githubLink ) . not . toBeNull ( ) ;
61+ expect ( githubLink ?. textContent ?. trim ( ) ) . toBe ( 'Fork me on GitHub' ) ;
3262 } ) ;
3363} ) ;
0 commit comments