Skip to content

Instantly share code, notes, and snippets.

@PavanKu
PavanKu / RenderPropPattern_Alternate.js
Created March 1, 2019 07:43
Render prop pattern alternate by using React.cloneElement method.
import React from 'react';
const ProductDetail = ({ product }) => (
<React.Fragment>
<h2>{product.title}</h2>
<div>{product.description}</div>
</React.Fragment>);
class Fetch extends React.Component {
@PavanKu
PavanKu / Cookie.md
Last active October 6, 2018 05:03
Interaction with Browser Cookie
@PavanKu
PavanKu / .txt
Created February 28, 2018 01:25
Copy Paste from Excel to ngPrime Datatable
//Component.html
<p-column *ngFor="let col of cols; let i = index" [field]="col.field" [header]="col.header">
<ng-template pTemplate="body" let-car="rowData">
<span *ngIf="car.editable" [attr.data-index]="i">
<input type="text" (keyup)="populate($event, i)" >
</span>
<span *ngIf="!car.editable">{{car[col.field]}}</span>
</ng-template>
</p-column>
@PavanKu
PavanKu / save-contact.component.spec.ts
Created January 22, 2018 04:30
Unit Testing of Component with Two Way Binding in AngularJS V5
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { SaveContactComponent } from './save-contact.component';
import { Contact } from '../models/contact';
import { DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
describe('SaveContactComponent', () => {
let component: SaveContactComponent;
let fixture: ComponentFixture<SaveContactComponent>;
@PavanKu
PavanKu / address-book.component.spec.ts
Last active January 22, 2018 04:31
Unit Testing of Component which Uses Service And Contain Child Component in AngularJS V5
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AddressBookComponent } from './address-book.component';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { AddressBookDataService } from '../services/address-book-data.service';
describe('AddressBookComponent', () => {
let component: AddressBookComponent;
let fixture: ComponentFixture<AddressBookComponent>;
let addressBookDataServiceStub: any;
@PavanKu
PavanKu / contact.component.spec.ts
Created January 22, 2018 04:27
Unit Testing a Component with Input and Output in AngularJS V5
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ContactComponent } from './contact.component';
import { Contact } from '../models/contact';
import { DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
describe('ContactComponent', () => {
let component: ContactComponent;
let fixture: ComponentFixture<ContactComponent>;
@PavanKu
PavanKu / header.component.spec.ts
Created January 22, 2018 04:25
Unit Testing of Simple Component in AngularJS V5
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HeaderComponent } from './header.component';
import { DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
describe('HeaderComponent', () => {
let component: HeaderComponent;
let fixture: ComponentFixture<HeaderComponent>;
@PavanKu
PavanKu / address-book-data.service.spec.ts
Created January 22, 2018 04:24
Unit Testing of Service in AngularJS V5
import { TestBed, inject } from '@angular/core/testing';
import { AddressBookDataService } from './address-book-data.service';
import { Contact } from '../models/contact';
describe('AddressBookDataService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [AddressBookDataService]
});
@PavanKu
PavanKu / contact.spec.ts
Created January 22, 2018 04:22
Unit Testing of Model Class In AngularJS V5
import { Contact } from './contact';
describe('Contact', () => {
it('should create an instance', () => {
expect(new Contact()).toBeTruthy();
});
it('should accept values from constructor', () => {
let contact = new Contact({
firstName: 'John',
@PavanKu
PavanKu / global.js
Created December 26, 2017 05:49
Global value
var count = 5;
function test () {
console.log(this.count === 5);
}
test() // Prints true as “count” variable declaration happened in global execution context so count will become part of global object.