feat(ExpressionParser): add support for this

This commit is contained in:
Victor Berchet
2016-08-04 10:14:44 -07:00
committed by Alex Rickabaugh
parent 26c9e1dc70
commit 0ca05eee45
9 changed files with 75 additions and 23 deletions

View File

@ -14,6 +14,8 @@ import {NgFor, NgIf} from '@angular/common';
import {expect} from '@angular/platform-browser/testing/matchers';
import {By} from '@angular/platform-browser/src/dom/debug/by';
let thisArg: any;
export function main() {
describe('ngFor', () => {
const TEMPLATE =
@ -460,6 +462,22 @@ export function main() {
}));
describe('track by', () => {
it('should set the context to the component instance',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
const template =
`<template ngFor let-item [ngForOf]="items" [ngForTrackBy]="trackByContext.bind(this)"></template>`;
tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((fixture) => {
thisArg = null;
fixture.detectChanges();
expect(thisArg).toBe(fixture.debugElement.componentInstance);
async.done();
});
}));
it('should not replace tracked items',
inject(
[TestComponentBuilder, AsyncTestCompleter],
@ -557,6 +575,7 @@ class TestComponent {
constructor() { this.items = [1, 2]; }
trackById(index: number, item: any): string { return item['id']; }
trackByIndex(index: number, item: any): number { return index; }
trackByContext(): void { thisArg = this; }
}
@Component({selector: 'outer-cmp', directives: [TestComponent], template: ''})