Skip to content

Instantly share code, notes, and snippets.

Stepan Suvorov stevermeister

Block or report user

Report or block stevermeister

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View forwardRef.source.ts
export function forwardRef(forwardRefFn: ForwardRefFn): Type<any> {
(<any>forwardRefFn).__forward_ref__ = forwardRef;
(<any>forwardRefFn).toString = function() { return stringify(this()); };
return (<Type<any>><any>forwardRefFn);
}
View forwardRef-full.ts
export const My_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => MyComponent),
multi: true
};
export class MyComponent {
//...
}
View forwardRef.ts
export const MY_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => MyComponent),
multi: true
};
View logclicks.directive.spec.ts
@Component({
selector: 'container',
template: '<div appLogClicks></div>'
})
export class Container {}
View logclicks.directive.spec.ts
import { LogClicksDirective } from './log-clicks.directive';
describe('LogClicksDirective', () => {
it('should create an instance', () => {
const directive = new LogClicksDirective();
expect(directive).toBeTruthy();
});
});
View logclicks.directive.ts
import { Directive, Output, EventEmitter, HostListener } from '@angular/core';
@Directive({
selector: '[logClicks]'
})
export class LogClicksDirective {
public couter = 0;
@Output() changes = new EventEmitter();
View user-card.component.spec.ts
it('should call UserService', () => {
component.someMethod();
expect(spy.calls.any()).toBeTruthy();
});
it('should set user', () => {
component.someMethod();
expect(component.user.name).toEqual('John');
});
View users.service.spy.ts
mockUser = {
name: 'John',
age: 21
};
spy = spyOn(userService, 'getOne').and.returnValue(Observable.of(mockUser));
View user-card.component.spec.ts
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { UserCardComponent } from './user-card.component';
describe('UserCardComponent', () => {
let component: UserCardComponent;
let fixture: ComponentFixture<UserCardComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
View user-card.component.ts
import { UserService } from '../user.service';
import { Component } from '@angular/core';
@Component({
selector: 'app-user-card',
template: '<div>{{user?.name}}</div>',
providers: [UserService]
})
export class UserCardComponent {
You can’t perform that action at this time.