Last active
May 26, 2017 08:30
-
-
Save chaosmonster/b7d3cf2024085592e88d9fa61779d069 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* | |
* Run the following code with `ng test` | |
* Is this a jasmine, typescript, angular or stupid developer bug? | |
**/ | |
import { | |
ComponentFactory, | |
ComponentRef, | |
ElementRef, | |
EmbeddedViewRef, | |
Injector, | |
TemplateRef, | |
ViewContainerRef, | |
ViewRef | |
} from '@angular/core'; | |
export class ViewContainerRefMock1 extends ViewContainerRef { | |
clear(): void { | |
} | |
get(index: number): ViewRef { | |
return undefined; | |
} | |
createEmbeddedView<C>(templateRef: TemplateRef<C>, context?: C, index?: number): EmbeddedViewRef<C> { | |
return undefined; | |
} | |
createComponent<C>(componentFactory: ComponentFactory<C>, index?: number, injector?: Injector, projectableNodes?: any[][]): ComponentRef<C> { | |
return undefined; | |
} | |
insert(viewRef: ViewRef, index?: number): ViewRef { | |
return undefined; | |
} | |
move(viewRef: ViewRef, currentIndex: number): ViewRef { | |
return undefined; | |
} | |
indexOf(viewRef: ViewRef): number { | |
return undefined; | |
} | |
remove(index?: number): void { | |
} | |
detach(index?: number): ViewRef { | |
return undefined; | |
} | |
constructor() { | |
super(); | |
} | |
_element: ElementRef = { | |
nativeElement: { | |
scrollTop: 0 | |
} | |
}; | |
get element(): ElementRef { | |
return this._element; | |
} | |
} | |
export class ViewContainerRefMock2 extends ViewContainerRef { | |
clear(): void { | |
} | |
get(index: number): ViewRef { | |
return undefined; | |
} | |
createEmbeddedView<C>(templateRef: TemplateRef<C>, context?: C, index?: number): EmbeddedViewRef<C> { | |
return undefined; | |
} | |
createComponent<C>(componentFactory: ComponentFactory<C>, index?: number, injector?: Injector, projectableNodes?: any[][]): ComponentRef<C> { | |
return undefined; | |
} | |
insert(viewRef: ViewRef, index?: number): ViewRef { | |
return undefined; | |
} | |
move(viewRef: ViewRef, currentIndex: number): ViewRef { | |
return undefined; | |
} | |
indexOf(viewRef: ViewRef): number { | |
return undefined; | |
} | |
remove(index?: number): void { | |
} | |
detach(index?: number): ViewRef { | |
return undefined; | |
} | |
constructor() { | |
super(); | |
} | |
public element: ElementRef = { | |
nativeElement: { | |
scrollTop: 0 | |
} | |
}; | |
} | |
export const scrollTop = (viewRef: ViewContainerRef, scrollTop: number) => { | |
viewRef.element.nativeElement.scrollTop = scrollTop; | |
}; | |
fdescribe('Function: scrollTop - working', () => { | |
let viewRef: ViewContainerRef; | |
beforeEach(() => { | |
viewRef = new ViewContainerRefMock1(); | |
}); | |
it('should set viewRef.element.nativeElement.scrollTop', () => { | |
scrollTop(viewRef, 23); | |
expect(viewRef.element.nativeElement.scrollTop).toBe(23); | |
}); | |
}); | |
fdescribe('Function: scrollTop - not working', () => { | |
let viewRef: ViewContainerRef; | |
beforeEach(() => { | |
viewRef = new ViewContainerRefMock2(); | |
}); | |
it('should set viewRef.element.nativeElement.scrollTop', () => { | |
scrollTop(viewRef, 23); | |
expect(viewRef.element.nativeElement.scrollTop).toBe(23); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment