2017-01-23 19:59:20 -05:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2017-09-22 17:29:16 -04:00
|
|
|
import {ElementRef, QueryList, TemplateRef, ViewContainerRef} from '@angular/core';
|
2017-01-27 16:19:00 -05:00
|
|
|
import {getDebugContext} from '@angular/core/src/errors';
|
2017-09-22 17:29:16 -04:00
|
|
|
import {NodeDef, NodeFlags, QueryBindingType, QueryValueType, Services, anchorDef, asElementData, asProviderData, attachEmbeddedView, detachEmbeddedView, directiveDef, elementDef, queryDef} from '@angular/core/src/view/index';
|
2017-01-23 19:59:20 -05:00
|
|
|
|
2017-09-22 17:29:16 -04:00
|
|
|
import {compViewDef, compViewDefFactory, createAndGetRootNodes, createEmbeddedView} from './helper';
|
2017-02-01 14:32:27 -05:00
|
|
|
|
2017-12-15 19:28:41 -05:00
|
|
|
{
|
2017-01-23 19:59:20 -05:00
|
|
|
describe(`Query Views`, () => {
|
|
|
|
|
2017-02-15 11:36:49 -05:00
|
|
|
const someQueryId = 1;
|
|
|
|
|
2017-01-23 19:59:20 -05:00
|
|
|
class AService {}
|
|
|
|
|
|
|
|
class QueryService {
|
2018-06-18 19:38:33 -04:00
|
|
|
// TODO(issue/24571): remove '!'.
|
|
|
|
a !: QueryList<AService>;
|
2017-01-23 19:59:20 -05:00
|
|
|
}
|
|
|
|
|
2017-09-22 17:29:16 -04:00
|
|
|
function contentQueryProviders(checkIndex: number) {
|
2017-01-25 16:45:07 -05:00
|
|
|
return [
|
2017-09-22 17:29:16 -04:00
|
|
|
directiveDef(checkIndex, NodeFlags.None, null, 1, QueryService, []),
|
2017-02-15 11:36:49 -05:00
|
|
|
queryDef(
|
2017-02-27 12:14:18 -05:00
|
|
|
NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
|
2017-02-15 11:36:49 -05:00
|
|
|
{'a': QueryBindingType.All})
|
2017-01-25 16:45:07 -05:00
|
|
|
];
|
2017-01-23 19:59:20 -05:00
|
|
|
}
|
|
|
|
|
2017-09-22 17:29:16 -04:00
|
|
|
const cQPLength = contentQueryProviders(0).length;
|
|
|
|
|
|
|
|
// nodes first checkIndex should be 1 (to account for the `queryDef`
|
|
|
|
function compViewQueryProviders(checkIndex: number, extraChildCount: number, nodes: NodeDef[]) {
|
2017-01-25 16:45:07 -05:00
|
|
|
return [
|
2017-02-21 16:56:56 -05:00
|
|
|
elementDef(
|
2017-09-22 17:29:16 -04:00
|
|
|
checkIndex, NodeFlags.None, null, null, 1 + extraChildCount, 'div', null, null, null,
|
|
|
|
null, () => compViewDef([
|
|
|
|
queryDef(
|
|
|
|
NodeFlags.TypeViewQuery | NodeFlags.DynamicQuery, someQueryId,
|
|
|
|
{'a': QueryBindingType.All}),
|
|
|
|
...nodes
|
|
|
|
])),
|
|
|
|
directiveDef(
|
|
|
|
checkIndex + 1, NodeFlags.Component, null !, 0, QueryService, [], null !, null !, ),
|
2017-01-25 16:45:07 -05:00
|
|
|
];
|
2017-01-23 19:59:20 -05:00
|
|
|
}
|
|
|
|
|
2017-09-22 17:29:16 -04:00
|
|
|
const cVQLength = compViewQueryProviders(0, 0, []).length;
|
|
|
|
|
|
|
|
|
|
|
|
function aServiceProvider(checkIndex: number) {
|
2017-02-15 11:36:49 -05:00
|
|
|
return directiveDef(
|
2017-09-22 17:29:16 -04:00
|
|
|
checkIndex, NodeFlags.None, [[someQueryId, QueryValueType.Provider]], 0, AService, []);
|
2017-01-23 19:59:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('content queries', () => {
|
|
|
|
|
|
|
|
it('should query providers on the same element and child elements', () => {
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-09-22 17:29:16 -04:00
|
|
|
elementDef(0, NodeFlags.None, null, null, 5, 'div'),
|
|
|
|
...contentQueryProviders(1),
|
|
|
|
aServiceProvider(1 + cQPLength),
|
|
|
|
elementDef(2 + cQPLength, NodeFlags.None, null, null, 1, 'div'),
|
|
|
|
aServiceProvider(3 + cQPLength),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-01-25 16:45:07 -05:00
|
|
|
const qs: QueryService = asProviderData(view, 1).instance;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(qs.a).toBeUndefined();
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
|
|
|
const as = qs.a.toArray();
|
|
|
|
expect(as.length).toBe(2);
|
2017-01-25 16:45:07 -05:00
|
|
|
expect(as[0]).toBe(asProviderData(view, 3).instance);
|
|
|
|
expect(as[1]).toBe(asProviderData(view, 5).instance);
|
2017-01-23 19:59:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not query providers on sibling or parent elements', () => {
|
2017-09-22 17:29:16 -04:00
|
|
|
|
2017-01-23 19:59:20 -05:00
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-09-22 17:29:16 -04:00
|
|
|
elementDef(0, NodeFlags.None, null, null, 6, 'div'),
|
|
|
|
aServiceProvider(1),
|
|
|
|
elementDef(2, NodeFlags.None, null, null, 2, 'div'),
|
|
|
|
...contentQueryProviders(3),
|
|
|
|
elementDef(3 + cQPLength, NodeFlags.None, null, null, 1, 'div'),
|
|
|
|
aServiceProvider(4 + cQPLength),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
2017-01-25 16:45:07 -05:00
|
|
|
const qs: QueryService = asProviderData(view, 3).instance;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(qs.a.length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('view queries', () => {
|
|
|
|
it('should query providers in the view', () => {
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-02-21 16:56:56 -05:00
|
|
|
...compViewQueryProviders(
|
2017-09-22 17:29:16 -04:00
|
|
|
0, 0,
|
2017-02-21 16:56:56 -05:00
|
|
|
[
|
2017-09-22 17:29:16 -04:00
|
|
|
elementDef(1, NodeFlags.None, null, null, 1, 'span'),
|
|
|
|
aServiceProvider(2),
|
2017-02-21 16:56:56 -05:00
|
|
|
]),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
2017-01-25 16:45:07 -05:00
|
|
|
const comp: QueryService = asProviderData(view, 1).instance;
|
2017-02-21 16:56:56 -05:00
|
|
|
const compView = asElementData(view, 0).componentView;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(comp.a.length).toBe(1);
|
2017-02-17 11:56:36 -05:00
|
|
|
expect(comp.a.first).toBe(asProviderData(compView, 2).instance);
|
2017-01-23 19:59:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not query providers on the host element', () => {
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-09-22 17:29:16 -04:00
|
|
|
...compViewQueryProviders(0, 1, [elementDef(1, NodeFlags.None, null, null, 0, 'span')]),
|
|
|
|
aServiceProvider(cVQLength),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-25 16:45:07 -05:00
|
|
|
const comp: QueryService = asProviderData(view, 1).instance;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(comp.a.length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('embedded views', () => {
|
|
|
|
it('should query providers in embedded views', () => {
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-09-22 17:29:16 -04:00
|
|
|
elementDef(0, NodeFlags.None, null, null, 5, 'div'),
|
|
|
|
...contentQueryProviders(1),
|
|
|
|
anchorDef(NodeFlags.EmbeddedViews, null, null, 2, null, compViewDefFactory([
|
|
|
|
elementDef(0, NodeFlags.None, null, null, 1, 'div'),
|
|
|
|
aServiceProvider(1),
|
2017-02-02 18:01:35 -05:00
|
|
|
])),
|
2017-09-22 17:29:16 -04:00
|
|
|
...contentQueryProviders(2 + cQPLength),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-05-15 16:12:10 -04:00
|
|
|
const childView = createEmbeddedView(view, view.def.nodes[3]);
|
2017-02-22 13:05:56 -05:00
|
|
|
attachEmbeddedView(view, asElementData(view, 3), 0, childView);
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
|
|
|
// queries on parent elements of anchors
|
2017-01-25 16:45:07 -05:00
|
|
|
const qs1: QueryService = asProviderData(view, 1).instance;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(qs1.a.length).toBe(1);
|
|
|
|
expect(qs1.a.first instanceof AService).toBe(true);
|
|
|
|
|
|
|
|
// queries on the anchor
|
2017-01-25 16:45:07 -05:00
|
|
|
const qs2: QueryService = asProviderData(view, 4).instance;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(qs2.a.length).toBe(1);
|
|
|
|
expect(qs2.a.first instanceof AService).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should query providers in embedded views only at the template declaration', () => {
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-09-22 17:29:16 -04:00
|
|
|
elementDef(0, NodeFlags.None, null, null, 3, 'div'),
|
|
|
|
...contentQueryProviders(1),
|
|
|
|
anchorDef(NodeFlags.EmbeddedViews, null, null, 0, null, compViewDefFactory([
|
|
|
|
elementDef(0, NodeFlags.None, null, null, 1, 'div'),
|
|
|
|
aServiceProvider(1),
|
2017-02-02 18:01:35 -05:00
|
|
|
])),
|
2017-09-22 17:29:16 -04:00
|
|
|
elementDef(2 + cQPLength, NodeFlags.None, null, null, 3, 'div'),
|
|
|
|
...contentQueryProviders(3 + cQPLength),
|
|
|
|
anchorDef(NodeFlags.EmbeddedViews, null, null, 0),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-05-15 16:12:10 -04:00
|
|
|
const childView = createEmbeddedView(view, view.def.nodes[3]);
|
2017-01-23 19:59:20 -05:00
|
|
|
// attach at a different place than the one where the template was defined
|
2017-02-22 13:05:56 -05:00
|
|
|
attachEmbeddedView(view, asElementData(view, 7), 0, childView);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
|
|
|
// query on the declaration place
|
2017-01-25 16:45:07 -05:00
|
|
|
const qs1: QueryService = asProviderData(view, 1).instance;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(qs1.a.length).toBe(1);
|
|
|
|
expect(qs1.a.first instanceof AService).toBe(true);
|
|
|
|
|
|
|
|
// query on the attach place
|
2017-01-25 16:45:07 -05:00
|
|
|
const qs2: QueryService = asProviderData(view, 5).instance;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(qs2.a.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update content queries if embedded views are added or removed', () => {
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-09-22 17:29:16 -04:00
|
|
|
elementDef(0, NodeFlags.None, null, null, 3, 'div'),
|
|
|
|
...contentQueryProviders(1),
|
|
|
|
anchorDef(NodeFlags.EmbeddedViews, null, null, 0, null, compViewDefFactory([
|
|
|
|
elementDef(0, NodeFlags.None, null, null, 1, 'div'),
|
|
|
|
aServiceProvider(1),
|
2017-02-02 18:01:35 -05:00
|
|
|
])),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
2017-01-25 16:45:07 -05:00
|
|
|
const qs: QueryService = asProviderData(view, 1).instance;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(qs.a.length).toBe(0);
|
|
|
|
|
2017-05-15 16:12:10 -04:00
|
|
|
const childView = createEmbeddedView(view, view.def.nodes[3]);
|
2017-02-22 13:05:56 -05:00
|
|
|
attachEmbeddedView(view, asElementData(view, 3), 0, childView);
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
|
|
|
expect(qs.a.length).toBe(1);
|
|
|
|
|
2017-01-25 16:45:07 -05:00
|
|
|
detachEmbeddedView(asElementData(view, 3), 0);
|
2017-02-22 13:05:56 -05:00
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
|
|
|
expect(qs.a.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update view queries if embedded views are added or removed', () => {
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-02-21 16:56:56 -05:00
|
|
|
...compViewQueryProviders(
|
2017-09-22 17:29:16 -04:00
|
|
|
0, 0,
|
2017-02-21 16:56:56 -05:00
|
|
|
[
|
2017-09-22 17:29:16 -04:00
|
|
|
anchorDef(NodeFlags.EmbeddedViews, null, null, 0, null, compViewDefFactory([
|
|
|
|
elementDef(0, NodeFlags.None, null, null, 1, 'div'),
|
|
|
|
aServiceProvider(1),
|
2017-02-21 16:56:56 -05:00
|
|
|
])),
|
|
|
|
]),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
2017-01-25 16:45:07 -05:00
|
|
|
const comp: QueryService = asProviderData(view, 1).instance;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(comp.a.length).toBe(0);
|
|
|
|
|
2017-02-21 16:56:56 -05:00
|
|
|
const compView = asElementData(view, 0).componentView;
|
2017-05-15 16:12:10 -04:00
|
|
|
const childView = createEmbeddedView(compView, compView.def.nodes[1]);
|
2017-02-22 13:05:56 -05:00
|
|
|
attachEmbeddedView(view, asElementData(compView, 1), 0, childView);
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
|
|
|
expect(comp.a.length).toBe(1);
|
|
|
|
|
2017-02-17 11:56:36 -05:00
|
|
|
detachEmbeddedView(asElementData(compView, 1), 0);
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
|
|
|
expect(comp.a.length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('QueryBindingType', () => {
|
|
|
|
it('should query all matches', () => {
|
|
|
|
class QueryService {
|
2018-06-18 19:38:33 -04:00
|
|
|
// TODO(issue/24571): remove '!'.
|
|
|
|
a !: QueryList<AService>;
|
2017-01-23 19:59:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-09-22 17:29:16 -04:00
|
|
|
elementDef(0, NodeFlags.None, null, null, 4, 'div'),
|
|
|
|
directiveDef(1, NodeFlags.None, null, 1, QueryService, []),
|
2017-02-15 11:36:49 -05:00
|
|
|
queryDef(
|
2017-02-27 12:14:18 -05:00
|
|
|
NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
|
2017-02-15 11:36:49 -05:00
|
|
|
{'a': QueryBindingType.All}),
|
2017-09-22 17:29:16 -04:00
|
|
|
aServiceProvider(3),
|
|
|
|
aServiceProvider(4),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
2017-01-25 16:45:07 -05:00
|
|
|
const qs: QueryService = asProviderData(view, 1).instance;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(qs.a instanceof QueryList).toBeTruthy();
|
|
|
|
expect(qs.a.toArray()).toEqual([
|
2017-01-25 16:45:07 -05:00
|
|
|
asProviderData(view, 3).instance,
|
|
|
|
asProviderData(view, 4).instance,
|
2017-01-23 19:59:20 -05:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should query the first match', () => {
|
|
|
|
class QueryService {
|
2018-06-18 19:38:33 -04:00
|
|
|
// TODO(issue/24571): remove '!'.
|
|
|
|
a !: AService;
|
2017-01-23 19:59:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-09-22 17:29:16 -04:00
|
|
|
elementDef(0, NodeFlags.None, null, null, 4, 'div'),
|
|
|
|
directiveDef(1, NodeFlags.None, null, 1, QueryService, []),
|
2017-02-15 11:36:49 -05:00
|
|
|
queryDef(
|
2017-02-27 12:14:18 -05:00
|
|
|
NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
|
2017-02-15 11:36:49 -05:00
|
|
|
{'a': QueryBindingType.First}),
|
2017-09-22 17:29:16 -04:00
|
|
|
aServiceProvider(3),
|
|
|
|
aServiceProvider(4),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
2017-01-25 16:45:07 -05:00
|
|
|
const qs: QueryService = asProviderData(view, 1).instance;
|
|
|
|
expect(qs.a).toBe(asProviderData(view, 3).instance);
|
2017-01-23 19:59:20 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('query builtins', () => {
|
|
|
|
it('should query ElementRef', () => {
|
|
|
|
class QueryService {
|
2018-06-18 19:38:33 -04:00
|
|
|
// TODO(issue/24571): remove '!'.
|
|
|
|
a !: ElementRef;
|
2017-01-23 19:59:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-09-22 17:29:16 -04:00
|
|
|
elementDef(0, NodeFlags.None, [[someQueryId, QueryValueType.ElementRef]], null, 2, 'div'),
|
|
|
|
directiveDef(1, NodeFlags.None, null, 1, QueryService, []),
|
2017-02-15 11:36:49 -05:00
|
|
|
queryDef(
|
2017-02-27 12:14:18 -05:00
|
|
|
NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
|
2017-02-15 11:36:49 -05:00
|
|
|
{'a': QueryBindingType.First}),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
2017-01-25 16:45:07 -05:00
|
|
|
const qs: QueryService = asProviderData(view, 1).instance;
|
|
|
|
expect(qs.a.nativeElement).toBe(asElementData(view, 0).renderElement);
|
2017-01-23 19:59:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should query TemplateRef', () => {
|
|
|
|
class QueryService {
|
2018-06-18 19:38:33 -04:00
|
|
|
// TODO(issue/24571): remove '!'.
|
|
|
|
a !: TemplateRef<any>;
|
2017-01-23 19:59:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
|
|
|
anchorDef(
|
2017-09-22 17:29:16 -04:00
|
|
|
NodeFlags.None, [[someQueryId, QueryValueType.TemplateRef]], null, 2, null,
|
|
|
|
compViewDefFactory([anchorDef(NodeFlags.None, null, null, 0)])),
|
|
|
|
directiveDef(1, NodeFlags.None, null, 1, QueryService, []),
|
2017-02-15 11:36:49 -05:00
|
|
|
queryDef(
|
2017-02-27 12:14:18 -05:00
|
|
|
NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
|
2017-02-15 11:36:49 -05:00
|
|
|
{'a': QueryBindingType.First}),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
2017-01-25 16:45:07 -05:00
|
|
|
const qs: QueryService = asProviderData(view, 1).instance;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(qs.a.createEmbeddedView).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should query ViewContainerRef', () => {
|
|
|
|
class QueryService {
|
2018-06-18 19:38:33 -04:00
|
|
|
// TODO(issue/24571): remove '!'.
|
|
|
|
a !: ViewContainerRef;
|
2017-01-23 19:59:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-03-13 13:44:12 -04:00
|
|
|
anchorDef(
|
2017-09-22 17:29:16 -04:00
|
|
|
NodeFlags.EmbeddedViews, [[someQueryId, QueryValueType.ViewContainerRef]], null, 2),
|
|
|
|
directiveDef(1, NodeFlags.None, null, 1, QueryService, []),
|
2017-02-15 11:36:49 -05:00
|
|
|
queryDef(
|
2017-02-27 12:14:18 -05:00
|
|
|
NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
|
2017-02-15 11:36:49 -05:00
|
|
|
{'a': QueryBindingType.First}),
|
2017-01-23 19:59:20 -05:00
|
|
|
]));
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-23 19:59:20 -05:00
|
|
|
|
2017-01-25 16:45:07 -05:00
|
|
|
const qs: QueryService = asProviderData(view, 1).instance;
|
2017-01-23 19:59:20 -05:00
|
|
|
expect(qs.a.createEmbeddedView).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2017-01-26 20:07:37 -05:00
|
|
|
|
|
|
|
describe('general binding behavior', () => {
|
|
|
|
it('should report debug info on binding errors', () => {
|
|
|
|
class QueryService {
|
|
|
|
set a(value: any) { throw new Error('Test'); }
|
|
|
|
}
|
|
|
|
|
|
|
|
const {view} = createAndGetRootNodes(compViewDef([
|
2017-09-22 17:29:16 -04:00
|
|
|
elementDef(0, NodeFlags.None, null, null, 3, 'div'),
|
|
|
|
directiveDef(1, NodeFlags.None, null, 1, QueryService, []),
|
2017-02-15 11:36:49 -05:00
|
|
|
queryDef(
|
2017-02-27 12:14:18 -05:00
|
|
|
NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
|
2017-02-15 11:36:49 -05:00
|
|
|
{'a': QueryBindingType.All}),
|
2017-09-22 17:29:16 -04:00
|
|
|
aServiceProvider(3),
|
2017-01-26 20:07:37 -05:00
|
|
|
]));
|
|
|
|
|
|
|
|
|
|
|
|
let err: any;
|
|
|
|
try {
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-26 20:07:37 -05:00
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
expect(err).toBeTruthy();
|
|
|
|
expect(err.message).toBe('Test');
|
2017-01-27 16:19:00 -05:00
|
|
|
const debugCtx = getDebugContext(err);
|
2017-01-26 20:07:37 -05:00
|
|
|
expect(debugCtx.view).toBe(view);
|
|
|
|
expect(debugCtx.nodeIndex).toBe(2);
|
|
|
|
});
|
|
|
|
});
|
2017-01-23 19:59:20 -05:00
|
|
|
});
|
2017-01-27 16:19:00 -05:00
|
|
|
}
|