@@ -73,6 +73,14 @@ List<ElementProbe> _findAllProbesInTree(dom.Node node) {
73
73
}
74
74
75
75
76
+ dom.Element _nearestElementAncestory (dom.Node node) {
77
+ if (node.nodeType == dom.Node .ELEMENT_NODE ) {
78
+ return node;
79
+ } else {
80
+ return _nearestElementAncestory (node.parentNode);
81
+ }
82
+ }
83
+
76
84
/**
77
85
* Return the [ElementProbe] object for the closest [Element] in the hierarchy.
78
86
*
@@ -279,30 +287,42 @@ class _Testability implements _JsObjectProxyable {
279
287
* Returns a list of all nodes in the selected tree that have an `ng-model`
280
288
* binding specified by the [modelString] . If the optional [exactMatch]
281
289
* parameter is provided and true, it restricts the searches to bindings that
282
- * are exact matches for [modelString] .
290
+ * are exact matches for [modelString] . If the optional [allowNonElementNodes]
291
+ * parameter is true, returned values will be the nearest parent node which is
292
+ * an element.
283
293
*/
284
- List <dom.Node > findModels (String modelString, [bool exactMatch]) => _findByExpression (
285
- modelString, exactMatch, (ElementProbe probe) => probe.modelExpressions);
294
+ List <dom.Node > findModels (String modelString, [bool exactMatch, bool allowNonElementNodes ]) => _findByExpression (
295
+ modelString, exactMatch, allowNonElementNodes, (ElementProbe probe) => probe.modelExpressions);
286
296
287
297
/**
288
298
* Returns a list of all nodes in the selected tree that have `ng-bind` or
289
299
* mustache bindings specified by the [bindingString] . If the optional
290
300
* [exactMatch] parameter is provided and true, it restricts the searches to
291
- * bindings that are exact matches for [bindingString] .
301
+ * bindings that are exact matches for [bindingString] . If the optional
302
+ * [allowNonElementNodes] parameter is true, returned values will be the nearest parent
303
+ * node which is an element.
292
304
*/
293
- List <dom.Node > findBindings (String bindingString, [bool exactMatch]) => _findByExpression (
294
- bindingString, exactMatch, (ElementProbe probe) => probe.bindingExpressions);
305
+ List <dom.Node > findBindings (String bindingString, [bool exactMatch, bool allowNonElementNodes]) => _findByExpression (
306
+ bindingString, exactMatch, allowNonElementNodes, (ElementProbe probe) => probe.bindingExpressions);
307
+
308
+ List <dom.Node > _findByExpression (String query, bool exactMatch, bool allowNonElementNodes, _GetExpressionsFromProbe getExpressions) {
295
309
296
- List <dom.Node > _findByExpression (String query, bool exactMatch, _GetExpressionsFromProbe getExpressions) {
297
310
List <ElementProbe > probes = _findAllProbesInTree (node);
298
311
if (probes.length == 0 ) {
299
312
probes.add (_findProbeWalkingUp (node));
300
313
}
301
314
List <dom.Node > results = [];
302
315
for (ElementProbe probe in probes) {
303
316
for (String expression in getExpressions (probe)) {
304
- if (exactMatch == true ? expression == query : expression.indexOf (query) >= 0 ) {
305
- results.add (probe.element);
317
+ if (exactMatch == true ? expression == query : expression.indexOf (query) >= 0 ) {
318
+ if (allowNonElementNodes == true ) {
319
+ results.add (probe.element);
320
+ } else {
321
+ var nearestElement = _nearestElementAncestory (probe.element);
322
+ if (! results.contains (nearestElement)) {
323
+ results.add (nearestElement);
324
+ }
325
+ }
306
326
}
307
327
}
308
328
}
@@ -319,10 +339,10 @@ class _Testability implements _JsObjectProxyable {
319
339
js.JsObject _toJsObject () {
320
340
return _jsify ({
321
341
'allowAnimations' : allowAnimations,
322
- 'findBindings' : (bindingString, [exactMatch]) =>
323
- findBindings (bindingString, exactMatch),
324
- 'findModels' : (modelExpressions, [exactMatch]) =>
325
- findModels (modelExpressions, exactMatch),
342
+ 'findBindings' : (bindingString, [exactMatch, allowNonElementNodes ]) =>
343
+ findBindings (bindingString, exactMatch, allowNonElementNodes ),
344
+ 'findModels' : (modelExpressions, [exactMatch, allowNonElementNodes ]) =>
345
+ findModels (modelExpressions, exactMatch, allowNonElementNodes ),
326
346
'whenStable' : (callback) =>
327
347
whenStable (() => callback.apply ([])),
328
348
'notifyWhenNoOutstandingRequests' : (callback) {
0 commit comments