Last active
May 31, 2020 04:28
-
-
Save night-fury-rider/f038782a06fe9786ee1279f6ccc495e0 to your computer and use it in GitHub Desktop.
Unit testing Angular Application using Jasmine - Home Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, OnDestroy, Input } from '@angular/core'; | |
import { Subscription } from 'rxjs/internal/Subscription'; | |
import uvData from './../../data/data.json'; | |
import { HomeService } from './home.service'; | |
@Component({ | |
selector: 'app-home', | |
templateUrl: './home.component.html', | |
styleUrls: ['./home.component.scss'] | |
}) | |
export class HomeComponent implements OnInit, OnDestroy { | |
@Input() appData: any; | |
searchBoxSubscription: Subscription; | |
uvCards = []; | |
uvActiveCards = []; | |
constructor(private homeService: HomeService) { | |
this.uvCards = uvData.cards; | |
this.uvActiveCards = JSON.parse(JSON.stringify(this.uvCards)); | |
this.homeService.get('Yuvraj Patil'); | |
} | |
ngOnInit(): void { | |
/** | |
* @description Function to subscribe to searchbox. | |
*/ | |
this.searchBoxSubscription = this.homeService.searchSubscriber$.subscribe(searchString => { | |
this.homeService.set(searchString); | |
}); | |
} | |
ngOnDestroy(): void { | |
if (this.searchBoxSubscription) { | |
this.searchBoxSubscription.unsubscribe(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment