fix(core): ensure initial value of QueryList length (#21980) (#21982)

Set initial value of `length` to `0`.

Fixes regression introduced by e544742156 (diff-a85dbe0991a7577ea24b49374e9ae90b) where the `length` property ceased to have initial value.

Closes #21980

PR Close #21982
This commit is contained in:
Emilio 2018-02-01 22:26:27 -08:00 committed by Miško Hevery
parent 64ae6d206e
commit e56de1025a
2 changed files with 17 additions and 1 deletions

View File

@ -41,7 +41,7 @@ export class QueryList<T>/* implements Iterable<T> */ {
private _results: Array<T> = [];
public readonly changes: Observable<any> = new EventEmitter();
readonly length: number;
readonly length: number = 0;
readonly first: T;
readonly last: T;

View File

@ -23,6 +23,22 @@ import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
function logAppend(item: any /** TODO #9100 */) { log += (log.length == 0 ? '' : ', ') + item; }
describe('dirty and reset', () => {
it('should initially be dirty and empty', () => {
expect(queryList.dirty).toBeTruthy();
expect(queryList.length).toBe(0);
});
it('should be not dirty after reset', () => {
expect(queryList.dirty).toBeTruthy();
queryList.reset(['one', 'two']);
expect(queryList.dirty).toBeFalsy();
expect(queryList.length).toBe(2);
});
});
it('should support resetting and iterating over the new objects', () => {
queryList.reset(['one']);
queryList.reset(['two']);