2016-06-23 12:47:54 -04: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
|
|
|
|
*/
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
|
2016-04-28 20:50:03 -04:00
|
|
|
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
|
|
|
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
|
|
|
import {Component, Directive} from '@angular/core';
|
|
|
|
import {ElementRef} from '@angular/core/src/linker/element_ref';
|
|
|
|
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
2015-05-26 17:22:35 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('non-bindable', () => {
|
2015-06-11 21:50:41 -04:00
|
|
|
it('should not interpolate children',
|
2016-06-08 19:38:52 -04:00
|
|
|
inject(
|
|
|
|
[TestComponentBuilder, AsyncTestCompleter],
|
|
|
|
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
|
|
|
var template = '<div>{{text}}<span ngNonBindable>{{text}}</span></div>';
|
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
|
|
|
.then((fixture) => {
|
|
|
|
fixture.detectChanges();
|
|
|
|
expect(fixture.debugElement.nativeElement).toHaveText('foo{{text}}');
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-05-26 17:22:35 -04:00
|
|
|
|
|
|
|
it('should ignore directives on child nodes',
|
2016-06-08 19:38:52 -04:00
|
|
|
inject(
|
|
|
|
[TestComponentBuilder, AsyncTestCompleter],
|
|
|
|
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
|
|
|
var template = '<div ngNonBindable><span id=child test-dec>{{text}}</span></div>';
|
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
|
|
|
.then((fixture) => {
|
|
|
|
fixture.detectChanges();
|
2015-06-24 16:07:15 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
// We must use getDOM().querySelector instead of fixture.query here
|
|
|
|
// since the elements inside are not compiled.
|
|
|
|
var span = getDOM().querySelector(fixture.debugElement.nativeElement, '#child');
|
|
|
|
expect(getDOM().hasClass(span, 'compiled')).toBeFalsy();
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-05-26 17:22:35 -04:00
|
|
|
|
|
|
|
it('should trigger directives on the same node',
|
2016-06-08 19:38:52 -04:00
|
|
|
inject(
|
|
|
|
[TestComponentBuilder, AsyncTestCompleter],
|
|
|
|
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
|
|
|
var template = '<div><span id=child ngNonBindable test-dec>{{text}}</span></div>';
|
|
|
|
tcb.overrideTemplate(TestComponent, template)
|
|
|
|
.createAsync(TestComponent)
|
|
|
|
.then((fixture) => {
|
|
|
|
fixture.detectChanges();
|
|
|
|
var span = getDOM().querySelector(fixture.debugElement.nativeElement, '#child');
|
|
|
|
expect(getDOM().hasClass(span, 'compiled')).toBeTruthy();
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
2015-05-26 17:22:35 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
@Directive({selector: '[test-dec]'})
|
|
|
|
class TestDirective {
|
2016-04-28 20:50:03 -04:00
|
|
|
constructor(el: ElementRef) { getDOM().addClass(el.nativeElement, 'compiled'); }
|
2015-05-26 17:22:35 -04:00
|
|
|
}
|
|
|
|
|
2016-03-08 16:36:48 -05:00
|
|
|
@Component({selector: 'test-cmp', directives: [TestDirective], template: ''})
|
2015-05-26 17:22:35 -04:00
|
|
|
class TestComponent {
|
|
|
|
text: string;
|
|
|
|
constructor() { this.text = 'foo'; }
|
|
|
|
}
|