fix(common): throw an error if trackBy is not a function (#13420)

* fix(common): throw an error if trackBy is not a function

Closes #13388

* refactor(platform-browser): disable no-console rule in DomAdapter
This commit is contained in:
Dzmitry Shylovich
2016-12-21 03:18:24 +03:00
committed by Chuck Jazdzewski
parent b9e979e0a5
commit 44e84d87f9
3 changed files with 22 additions and 4 deletions

View File

@ -294,6 +294,16 @@ export function main() {
}));
describe('track by', () => {
it('should throw if trackBy is not a function', async(() => {
const template =
`<template ngFor let-item [ngForOf]="items" [ngForTrackBy]="item?.id"></template>`;
fixture = createTestComponent(template);
getComponent().items = [{id: 1}, {id: 2}];
expect(() => fixture.detectChanges())
.toThrowError(/trackBy must be a function, but received null/);
}));
it('should set the context to the component instance', async(() => {
const template =
`<template ngFor let-item [ngForOf]="items" [ngForTrackBy]="trackByContext.bind(this)"></template>`;