Skip to content

Instantly share code, notes, and snippets.

View manivelarjunan's full-sized avatar

manivelarjunan

View GitHub Profile
import { Injectable } from '@angular/core';
@Injectable()
export class UserService {
user = {
name: 'Mannie'
};
getUser() {
return this.user;
import { async, TestBed } from '@angular/core/testing';
import { UserComponent } from './user.component';
import { UserService } from './user.service';
describe('UserComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [UserComponent]
<p *ngIf="systemError">{{systemErrorMessage}}</p>
<div *ngIf="isLoggedIn && !systemError">
<p>
{{userDetail.name}}
</p>
<p>Note: Above user details returned by async call.</p>
</div>
<div *ngIf="!isLoggedIn && !systemError">
<p>
import { Component, OnInit } from '@angular/core';
import { UserAsyncService } from './user-async.service';
import { Observable } from 'rxjs';
@Component({
selector: 'app-user-async',
templateUrl: './user-async.component.html',
styleUrls: ['./user-async.component.scss'],
providers: [UserAsyncService]
})
import { TestBed, tick, fakeAsync } from '@angular/core/testing';
import { UserAsyncComponent } from './user-async.component';
import { UserAsyncService } from './user-async.service';
import { Observable, Observer } from 'rxjs';
describe('User Async Component:', () => {
beforeEach(async () => {
TestBed.configureTestingModule({
declarations: [UserAsyncComponent]
});
import { Observable, Observer } from 'rxjs';
export class UserAsyncService {
user = { name: 'Mannie' };
getUserDetails() {
// Create an observables.
const userObservables = Observable.create(
(observer: Observer<{ name: string }>) => {
setTimeout(() => {
observer.next(this.user);
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'reversePipe'
})
export class ReversePipe implements PipeTransform {
transform(value: any, args?: any): any {
return value
.split('')
.reverse()
import { ReversePipe } from './reverse-value.pipe';
// Isolated test case.
describe('ReversePipe', () => {
it('create an instance', () => {
const pipe = new ReversePipe();
expect(pipe).toBeTruthy();
expect(pipe.transform('olleh')).toBe('hello');
});
});
export interface GoogleData {
id: number;
country: string;
zipCode: string;
}
@manivelarjunan
manivelarjunan / App.js
Last active March 17, 2019 20:59
React hook - functional based component
import React, { useState } from 'react';
import Person from './Person/Person';
import './App.css';
//class App extends Component {
const app = props => {
const [personsState,setPersonState] = useState({
persons: [
{name:'mani',age:45},
{name:'papi',age:34}