Skip to content

Instantly share code, notes, and snippets.

View night-fury-rider's full-sized avatar

Yuvraj Patil night-fury-rider

View GitHub Profile
@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.
}
@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 / 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 / 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 / uv-util.service.spec.ts
Last active May 31, 2020 04:31
Unit testing Angular Application using Jasmine - Util Service spec
import { TestBed } from '@angular/core/testing';
import * as globalmocks from '../globalmocks';
import { UvUtilService } from './uv-util.service';
describe('UvUtilService', () => {
let service: UvUtilService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(UvUtilService);
@night-fury-rider
night-fury-rider / Basic Closure.js
Last active July 3, 2020 13:35
What we need is closure - Basic
var sodexoAmount = 25;
function getSalary(baseSalary) {
var transportAmount = 50;
function calculateSalary(hraAmount) {
var specialAllowance = 75;
return specialAllowance + hraAmount + baseSalary + transportAmount + sodexoAmount;
}
return calculateSalary;
}
var monthlySalary = getSalary(100);
@night-fury-rider
night-fury-rider / setTimeout.js
Last active July 3, 2020 13:48
Basic SetTimeout
var numberOfKingdoms = 7;
setTimeout(function(){
alert('Jon should be king of ' + numberOfKingdoms + ' kingdoms');
}, 500);
@night-fury-rider
night-fury-rider / setInterval.js
Created June 24, 2020 03:02
Basic setInterval
var numberOfKingdoms = 7;
setInterval(function(){
alert('Jon should be king of ' + numberOfKingdoms + ' kingdoms');
}, 500)
document.getElementById("add-user").addEventListener("click", addUser);
function addUser() {
console.log('User has been added');
}
var uvHttp = new XMLHttpRequest();
uvHttp.onreadystatechange = function() {
console.log('HTTP state change callback executed');
};
uvHttp.open("GET", "/getUser", true);
uvHttp.send();