From 35a83b495a308793d173c054175becea12094839 Mon Sep 17 00:00:00 2001 From: gdi2290 Date: Mon, 27 Jul 2015 17:24:42 -0700 Subject: [PATCH] feat(query_list): delegate `toString` to `_results` array Closes #3004 --- modules/angular2/src/core/compiler/query_list.dart | 3 +++ modules/angular2/src/core/compiler/query_list.ts | 2 ++ modules/angular2/test/core/compiler/query_list_spec.ts | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/modules/angular2/src/core/compiler/query_list.dart b/modules/angular2/src/core/compiler/query_list.dart index 5cd008fdbd..4250ced31b 100644 --- a/modules/angular2/src/core/compiler/query_list.dart +++ b/modules/angular2/src/core/compiler/query_list.dart @@ -108,6 +108,9 @@ class QueryList extends Object int get length => _results.length; T get first => _results.first; T get last => _results.last; + String toString() { + return _results.toString(); + } List map(fn(T)) { // Note: we need to return a list instead of iterable to match JS. diff --git a/modules/angular2/src/core/compiler/query_list.ts b/modules/angular2/src/core/compiler/query_list.ts index 8154bf078d..bd57057e2f 100644 --- a/modules/angular2/src/core/compiler/query_list.ts +++ b/modules/angular2/src/core/compiler/query_list.ts @@ -97,6 +97,8 @@ export class QueryList { removeCallback(callback: () => void): void { ListWrapper.remove(this._callbacks, callback); } + toString(): string { return this._results.toString(); } + get length(): number { return this._results.length; } get first(): T { return ListWrapper.first(this._results); } get last(): T { return ListWrapper.last(this._results); } diff --git a/modules/angular2/test/core/compiler/query_list_spec.ts b/modules/angular2/test/core/compiler/query_list_spec.ts index 5a8684ebb9..7d26c87b94 100644 --- a/modules/angular2/test/core/compiler/query_list_spec.ts +++ b/modules/angular2/test/core/compiler/query_list_spec.ts @@ -1,6 +1,7 @@ import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/test_lib'; import {List, MapWrapper, ListWrapper, iterateListLike} from 'angular2/src/facade/collection'; +import {StringWrapper} from 'angular2/src/facade/lang'; import {QueryList} from 'angular2/src/core/compiler/query_list'; @@ -43,6 +44,14 @@ export function main() { expect(queryList.map((x) => x)).toEqual(['one', 'two']); }); + it('should support toString', () => { + queryList.add('one'); + queryList.add('two'); + var listString = queryList.toString(); + expect(StringWrapper.contains(listString, 'one')).toBeTruthy(); + expect(StringWrapper.contains(listString, 'two')).toBeTruthy(); + }); + it('should support first and last', () => { queryList.add('one'); queryList.add('two');