Skip to content

Instantly share code, notes, and snippets.

@night-fury-rider
Last active May 31, 2020 04:28
Show Gist options
  • Save night-fury-rider/f038782a06fe9786ee1279f6ccc495e0 to your computer and use it in GitHub Desktop.
Save night-fury-rider/f038782a06fe9786ee1279f6ccc495e0 to your computer and use it in GitHub Desktop.
Unit testing Angular Application using Jasmine - Home Component
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