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 }} */
|
/** <input value="one" #myInput> {{ myInput.value }} */
|
||||||
function Template(ctx: any, cm: boolean) {
|
function Template(ctx: any, cm: boolean) {
|
||||||
if (cm) {
|
if (cm) {
|
||||||
elementStart(0, 'input', ['value', 'one']);
|
elementStart(0, 'input', ['value', 'one'], null, ['myInput', '']);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
text(1);
|
text(1);
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ describe('exports', () => {
|
|||||||
/** <comp #myComp></comp> {{ myComp.name }} */
|
/** <comp #myComp></comp> {{ myComp.name }} */
|
||||||
function Template(ctx: any, cm: boolean) {
|
function Template(ctx: any, cm: boolean) {
|
||||||
if (cm) {
|
if (cm) {
|
||||||
elementStart(0, MyComponent);
|
elementStart(0, MyComponent, null, null, ['myComp', '']);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
text(2);
|
text(2);
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ describe('exports', () => {
|
|||||||
/** <comp #myComp></comp> <div [myDir]="myComp"></div> */
|
/** <comp #myComp></comp> <div [myDir]="myComp"></div> */
|
||||||
function Template(ctx: any, cm: boolean) {
|
function Template(ctx: any, cm: boolean) {
|
||||||
if (cm) {
|
if (cm) {
|
||||||
elementStart(0, MyComponent);
|
elementStart(0, MyComponent, null, null, ['myComp', '']);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
elementStart(2, 'div', null, [MyDir]);
|
elementStart(2, 'div', null, [MyDir]);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
@ -95,7 +95,7 @@ describe('exports', () => {
|
|||||||
/** <div someDir #myDir="someDir"></div> {{ myDir.name }} */
|
/** <div someDir #myDir="someDir"></div> {{ myDir.name }} */
|
||||||
function Template(ctx: any, cm: boolean) {
|
function Template(ctx: any, cm: boolean) {
|
||||||
if (cm) {
|
if (cm) {
|
||||||
elementStart(0, 'div', null, [SomeDir]);
|
elementStart(0, 'div', null, [SomeDir], ['myDir', 'someDir']);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
text(2);
|
text(2);
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ describe('exports', () => {
|
|||||||
function Template(ctx: any, cm: boolean) {
|
function Template(ctx: any, cm: boolean) {
|
||||||
if (cm) {
|
if (cm) {
|
||||||
text(0);
|
text(0);
|
||||||
elementStart(1, 'input', ['value', 'one']);
|
elementStart(1, 'input', ['value', 'one'], null, ['myInput', '']);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
}
|
}
|
||||||
let myInput = elementStart(1);
|
let myInput = elementStart(1);
|
||||||
@ -133,7 +133,7 @@ describe('exports', () => {
|
|||||||
if (cm) {
|
if (cm) {
|
||||||
elementStart(0, 'div');
|
elementStart(0, 'div');
|
||||||
elementEnd();
|
elementEnd();
|
||||||
elementStart(1, 'input', ['value', 'one']);
|
elementStart(1, 'input', ['value', 'one'], null, ['myInput', '']);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
}
|
}
|
||||||
let myInput = elementStart(1);
|
let myInput = elementStart(1);
|
||||||
@ -149,7 +149,7 @@ describe('exports', () => {
|
|||||||
if (cm) {
|
if (cm) {
|
||||||
elementStart(0, 'div');
|
elementStart(0, 'div');
|
||||||
elementEnd();
|
elementEnd();
|
||||||
elementStart(1, 'input', ['value', 'one']);
|
elementStart(1, 'input', ['value', 'one'], null, ['myInput', '']);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
}
|
}
|
||||||
let myInput = elementStart(1);
|
let myInput = elementStart(1);
|
||||||
@ -165,7 +165,7 @@ describe('exports', () => {
|
|||||||
if (cm) {
|
if (cm) {
|
||||||
elementStart(0, 'div');
|
elementStart(0, 'div');
|
||||||
elementEnd();
|
elementEnd();
|
||||||
elementStart(1, 'input', ['type', 'checkbox', 'checked', 'true']);
|
elementStart(1, 'input', ['type', 'checkbox', 'checked', 'true'], null, ['myInput', '']);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
}
|
}
|
||||||
let myInput = elementStart(1);
|
let myInput = elementStart(1);
|
||||||
@ -206,7 +206,7 @@ describe('exports', () => {
|
|||||||
if (cm) {
|
if (cm) {
|
||||||
elementStart(0, 'div', null, [MyDir]);
|
elementStart(0, 'div', null, [MyDir]);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
elementStart(2, MyComponent);
|
elementStart(2, MyComponent, null, null, ['myComp', '']);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
}
|
}
|
||||||
elementProperty(0, 'myDir', bind(load<MyComponent>(3)));
|
elementProperty(0, 'myDir', bind(load<MyComponent>(3)));
|
||||||
@ -223,9 +223,9 @@ describe('exports', () => {
|
|||||||
if (cm) {
|
if (cm) {
|
||||||
text(0);
|
text(0);
|
||||||
text(1);
|
text(1);
|
||||||
elementStart(2, MyComponent);
|
elementStart(2, MyComponent, null, null, ['myComp', '']);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
elementStart(4, 'input', ['value', 'one']);
|
elementStart(4, 'input', ['value', 'one'], null, ['myInput', '']);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
}
|
}
|
||||||
let myInput = elementStart(4);
|
let myInput = elementStart(4);
|
||||||
@ -265,7 +265,7 @@ describe('exports', () => {
|
|||||||
{
|
{
|
||||||
if (cm1) {
|
if (cm1) {
|
||||||
text(0);
|
text(0);
|
||||||
elementStart(1, 'input', ['value', 'one']);
|
elementStart(1, 'input', ['value', 'one'], null, ['myInput', '']);
|
||||||
elementEnd();
|
elementEnd();
|
||||||
}
|
}
|
||||||
let myInput = elementStart(1);
|
let myInput = elementStart(1);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* 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 {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 {container, containerRefreshEnd, containerRefreshStart, elementEnd, elementStart, embeddedViewEnd, embeddedViewStart, load} from '../../src/render3/instructions';
|
||||||
import {query, queryRefresh} from '../../src/render3/query';
|
import {query, queryRefresh} from '../../src/render3/query';
|
||||||
|
|
||||||
@ -372,7 +372,7 @@ describe('query', () => {
|
|||||||
|
|
||||||
let childInstance;
|
let childInstance;
|
||||||
/**
|
/**
|
||||||
* <cmpt #foo></cmpt>
|
* <child #foo></child>
|
||||||
* class Cmpt {
|
* class Cmpt {
|
||||||
* @ViewChildren('foo') query;
|
* @ViewChildren('foo') query;
|
||||||
* }
|
* }
|
||||||
@ -394,6 +394,41 @@ describe('query', () => {
|
|||||||
expect(qList.first).toBe(childInstance);
|
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',
|
it('should read directive instance if element queried for has an exported directive with a matching name',
|
||||||
() => {
|
() => {
|
||||||
const Child = createDirective({exportAs: 'child'});
|
const Child = createDirective({exportAs: 'child'});
|
||||||
@ -454,7 +489,7 @@ describe('query', () => {
|
|||||||
expect(qList.last).toBe(child2Instance);
|
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'});
|
const Child = createDirective({exportAs: 'child'});
|
||||||
|
|
||||||
let div;
|
let div;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user