angular-cn/modules/@angular/compiler-cli/integrationtest/test/query_spec.ts

36 lines
1.4 KiB
TypeScript

/**
* @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
*/
import './init';
import {DebugElement, QueryList} from '@angular/core';
import {By} from '@angular/platform-browser';
import {CompForChildQuery, CompWithChildQuery} from '../src/queries';
import {createComponent} from './util';
describe('child queries', () => {
it('should support compiling child queries', () => {
var childQueryCompFixture = createComponent(CompWithChildQuery);
var debugElement = childQueryCompFixture.debugElement;
var compWithChildren = debugElement.query(By.directive(CompWithChildQuery));
expect(childQueryCompFixture.componentInstance.child).toBeDefined();
expect(childQueryCompFixture.componentInstance.child instanceof CompForChildQuery).toBe(true);
});
it('should support compiling children queries', () => {
var childQueryCompFixture = createComponent(CompWithChildQuery);
var debugElement = childQueryCompFixture.debugElement;
var compWithChildren = debugElement.query(By.directive(CompWithChildQuery));
childQueryCompFixture.detectChanges();
expect(childQueryCompFixture.componentInstance.children).toBeDefined();
expect(childQueryCompFixture.componentInstance.children instanceof QueryList).toBe(true);
});
});