Skip to content

Instantly share code, notes, and snippets.

@night-fury-rider
night-fury-rider / uv-util.service.ts
Created May 31, 2020 04:00
Unit testing Angular Application using Jasmine - Util Service
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class UvUtilService {
constructor() { }
/**
@night-fury-rider
night-fury-rider / home.component.spec.ts
Last active May 31, 2020 04:29
Unit testing Angular Application using Jasmine - Home Component Spec
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HomeComponent } from './home.component';
import { HomeService } from './home.service';
import * as globalmocks from '../globalmocks'; // import everything which is present in globalmocks
// Function to reset to globalmocks.
const resetToGlobalMocks = () => {
globalmocks.HomeService.searchSubscriber$ = {
subscribe: (callback) => {
callback('Yuvraj');
@night-fury-rider
night-fury-rider / home.component.ts
Last active May 31, 2020 04:28
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']
})
@night-fury-rider
night-fury-rider / globalmocks.ts
Last active May 31, 2020 03:40
Unit testing Angular Application using Jasmine - globalmocks
// Use shollow copy of your app data.
export const appData = {
defaultOrderIndex: 0,
sortOrders: [{
type: 'string',
name: 'Title',
sortAttribute: 'title'
}]
// Remaining test data should be added here.
}