test(ivy): correct export tests and add query test (#22807)
PR Close #22807
This commit is contained in:
parent
b149424b11
commit
9220521149
|
@ -17,7 +17,7 @@ describe('exports', () => {
|
|||
/** <input value="one" #myInput> {{ myInput.value }} */
|
||||
function Template(ctx: any, cm: boolean) {
|
||||
if (cm) {
|
||||
elementStart(0, 'input', ['value', 'one']);
|
||||
elementStart(0, 'input', ['value', 'one'], null, ['myInput', '']);
|
||||
elementEnd();
|
||||
text(1);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ describe('exports', () => {
|
|||
/** <comp #myComp></comp> {{ myComp.name }} */
|
||||
function Template(ctx: any, cm: boolean) {
|
||||
if (cm) {
|
||||
elementStart(0, MyComponent);
|
||||
elementStart(0, MyComponent, null, null, ['myComp', '']);
|
||||
elementEnd();
|
||||
text(2);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ describe('exports', () => {
|
|||
/** <comp #myComp></comp> <div [myDir]="myComp"></div> */
|
||||
function Template(ctx: any, cm: boolean) {
|
||||
if (cm) {
|
||||
elementStart(0, MyComponent);
|
||||
elementStart(0, MyComponent, null, null, ['myComp', '']);
|
||||
elementEnd();
|
||||
elementStart(2, 'div', null, [MyDir]);
|
||||
elementEnd();
|
||||
|
@ -95,7 +95,7 @@ describe('exports', () => {
|
|||
/** <div someDir #myDir="someDir"></div> {{ myDir.name }} */
|
||||
function Template(ctx: any, cm: boolean) {
|
||||
if (cm) {
|
||||
elementStart(0, 'div', null, [SomeDir]);
|
||||
elementStart(0, 'div', null, [SomeDir], ['myDir', 'someDir']);
|
||||
elementEnd();
|
||||
text(2);
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ describe('exports', () => {
|
|||
function Template(ctx: any, cm: boolean) {
|
||||
if (cm) {
|
||||
text(0);
|
||||
elementStart(1, 'input', ['value', 'one']);
|
||||
elementStart(1, 'input', ['value', 'one'], null, ['myInput', '']);
|
||||
elementEnd();
|
||||
}
|
||||
let myInput = elementStart(1);
|
||||
|
@ -133,7 +133,7 @@ describe('exports', () => {
|
|||
if (cm) {
|
||||
elementStart(0, 'div');
|
||||
elementEnd();
|
||||
elementStart(1, 'input', ['value', 'one']);
|
||||
elementStart(1, 'input', ['value', 'one'], null, ['myInput', '']);
|
||||
elementEnd();
|
||||
}
|
||||
let myInput = elementStart(1);
|
||||
|
@ -149,7 +149,7 @@ describe('exports', () => {
|
|||
if (cm) {
|
||||
elementStart(0, 'div');
|
||||
elementEnd();
|
||||
elementStart(1, 'input', ['value', 'one']);
|
||||
elementStart(1, 'input', ['value', 'one'], null, ['myInput', '']);
|
||||
elementEnd();
|
||||
}
|
||||
let myInput = elementStart(1);
|
||||
|
@ -165,7 +165,7 @@ describe('exports', () => {
|
|||
if (cm) {
|
||||
elementStart(0, 'div');
|
||||
elementEnd();
|
||||
elementStart(1, 'input', ['type', 'checkbox', 'checked', 'true']);
|
||||
elementStart(1, 'input', ['type', 'checkbox', 'checked', 'true'], null, ['myInput', '']);
|
||||
elementEnd();
|
||||
}
|
||||
let myInput = elementStart(1);
|
||||
|
@ -206,7 +206,7 @@ describe('exports', () => {
|
|||
if (cm) {
|
||||
elementStart(0, 'div', null, [MyDir]);
|
||||
elementEnd();
|
||||
elementStart(2, MyComponent);
|
||||
elementStart(2, MyComponent, null, null, ['myComp', '']);
|
||||
elementEnd();
|
||||
}
|
||||
elementProperty(0, 'myDir', bind(load<MyComponent>(3)));
|
||||
|
@ -223,9 +223,9 @@ describe('exports', () => {
|
|||
if (cm) {
|
||||
text(0);
|
||||
text(1);
|
||||
elementStart(2, MyComponent);
|
||||
elementStart(2, MyComponent, null, null, ['myComp', '']);
|
||||
elementEnd();
|
||||
elementStart(4, 'input', ['value', 'one']);
|
||||
elementStart(4, 'input', ['value', 'one'], null, ['myInput', '']);
|
||||
elementEnd();
|
||||
}
|
||||
let myInput = elementStart(4);
|
||||
|
@ -265,7 +265,7 @@ describe('exports', () => {
|
|||
{
|
||||
if (cm1) {
|
||||
text(0);
|
||||
elementStart(1, 'input', ['value', 'one']);
|
||||
elementStart(1, 'input', ['value', 'one'], null, ['myInput', '']);
|
||||
elementEnd();
|
||||
}
|
||||
let myInput = elementStart(1);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {QUERY_READ_CONTAINER_REF, QUERY_READ_ELEMENT_REF, QUERY_READ_FROM_NODE, QUERY_READ_TEMPLATE_REF} from '../../src/render3/di';
|
||||
import {QueryList, detectChanges} from '../../src/render3/index';
|
||||
import {QueryList, detectChanges, defineComponent} from '../../src/render3/index';
|
||||
import {container, containerRefreshEnd, containerRefreshStart, elementEnd, elementStart, embeddedViewEnd, embeddedViewStart, load} from '../../src/render3/instructions';
|
||||
import {query, queryRefresh} from '../../src/render3/query';
|
||||
|
||||
|
@ -372,7 +372,7 @@ describe('query', () => {
|
|||
|
||||
let childInstance;
|
||||
/**
|
||||
* <cmpt #foo></cmpt>
|
||||
* <child #foo></child>
|
||||
* class Cmpt {
|
||||
* @ViewChildren('foo') query;
|
||||
* }
|
||||
|
@ -394,6 +394,41 @@ describe('query', () => {
|
|||
expect(qList.first).toBe(childInstance);
|
||||
});
|
||||
|
||||
it('should read component instance with explicit exportAs', () => {
|
||||
let childInstance: Child;
|
||||
|
||||
class Child {
|
||||
static ngComponentDef = defineComponent({
|
||||
type: Child,
|
||||
tag: 'child',
|
||||
factory: () => childInstance = new Child(),
|
||||
template: (ctx: Child, cm: boolean) => {},
|
||||
exportAs: 'child'
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <child #foo="child"></child>
|
||||
* class Cmpt {
|
||||
* @ViewChildren('foo') query;
|
||||
* }
|
||||
*/
|
||||
const Cmpt = createComponent('cmpt', function(ctx: any, cm: boolean) {
|
||||
let tmp: any;
|
||||
if (cm) {
|
||||
query(0, ['foo'], true, QUERY_READ_FROM_NODE);
|
||||
elementStart(1, Child, null, null, ['foo', 'child']);
|
||||
elementEnd();
|
||||
}
|
||||
queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>);
|
||||
});
|
||||
|
||||
const cmptInstance = renderComponent(Cmpt);
|
||||
const qList = (cmptInstance.query as QueryList<any>);
|
||||
expect(qList.length).toBe(1);
|
||||
expect(qList.first).toBe(childInstance !);
|
||||
});
|
||||
|
||||
it('should read directive instance if element queried for has an exported directive with a matching name',
|
||||
() => {
|
||||
const Child = createDirective({exportAs: 'child'});
|
||||
|
@ -454,7 +489,7 @@ describe('query', () => {
|
|||
expect(qList.last).toBe(child2Instance);
|
||||
});
|
||||
|
||||
it('should match match on exported directive name and read a requested token', () => {
|
||||
it('should match on exported directive name and read a requested token', () => {
|
||||
const Child = createDirective({exportAs: 'child'});
|
||||
|
||||
let div;
|
||||
|
|
Loading…
Reference in New Issue