This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Inject, Injectable } from '@angular/core'; | |
import { | |
BaseRequestOptions, | |
Headers, | |
Http, | |
Request, | |
RequestOptionsArgs, | |
Response, | |
URLSearchParams, | |
XHRBackend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function forwardRef(forwardRefFn: ForwardRefFn): Type<any> { | |
(<any>forwardRefFn).__forward_ref__ = forwardRef; | |
(<any>forwardRefFn).toString = function() { return stringify(this()); }; | |
return (<Type<any>><any>forwardRefFn); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const My_ACCESSOR = { | |
provide: NG_VALUE_ACCESSOR, | |
useExisting: forwardRef(() => MyComponent), | |
multi: true | |
}; | |
export class MyComponent { | |
//... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const MY_ACCESSOR = { | |
provide: NG_VALUE_ACCESSOR, | |
useExisting: forwardRef(() => MyComponent), | |
multi: true | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'container', | |
template: '<div appLogClicks></div>' | |
}) | |
export class Container {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LogClicksDirective } from './log-clicks.directive'; | |
describe('LogClicksDirective', () => { | |
it('should create an instance', () => { | |
const directive = new LogClicksDirective(); | |
expect(directive).toBeTruthy(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, Output, EventEmitter, HostListener } from '@angular/core'; | |
@Directive({ | |
selector: '[logClicks]' | |
}) | |
export class LogClicksDirective { | |
public couter = 0; | |
@Output() changes = new EventEmitter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should call UserService', () => { | |
component.someMethod(); | |
expect(spy.calls.any()).toBeTruthy(); | |
}); | |
it('should set user', () => { | |
component.someMethod(); | |
expect(component.user.name).toEqual('John'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mockUser = { | |
name: 'John', | |
age: 21 | |
}; | |
spy = spyOn(userService, 'getOne').and.returnValue(Observable.of(mockUser)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({ |