|
| 1 | +import {Component} from '@angular/core'; |
| 2 | +import {async, TestBed} from '@angular/core/testing'; |
| 3 | +import {ObserveContentModule} from './observe-content'; |
| 4 | + |
| 5 | +/** |
| 6 | + * TODO(elad): `ProxyZone` doesn't seem to capture the events raised by |
| 7 | + * `MutationObserver` and needs to be investigated |
| 8 | + */ |
| 9 | + |
| 10 | +describe('Observe content', () => { |
| 11 | + beforeEach(async(() => { |
| 12 | + TestBed.configureTestingModule({ |
| 13 | + imports: [ObserveContentModule], |
| 14 | + declarations: [ComponentWithTextContent, ComponentWithChildTextContent], |
| 15 | + }); |
| 16 | + |
| 17 | + TestBed.compileComponents(); |
| 18 | + })); |
| 19 | + |
| 20 | + describe('text content change', () => { |
| 21 | + it('should call the registered for changes function', done => { |
| 22 | + let fixture = TestBed.createComponent(ComponentWithTextContent); |
| 23 | + fixture.detectChanges(); |
| 24 | + |
| 25 | + // If the hint label is empty, expect no label. |
| 26 | + const spy = spyOn(fixture.componentInstance, 'doSomething').and.callFake(() => { |
| 27 | + expect(spy.calls.any()).toBe(true); |
| 28 | + done(); |
| 29 | + }); |
| 30 | + |
| 31 | + expect(spy.calls.any()).toBe(false); |
| 32 | + |
| 33 | + fixture.componentInstance.text = 'text'; |
| 34 | + fixture.detectChanges(); |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + describe('child text content change', () => { |
| 39 | + it('should call the registered for changes function', done => { |
| 40 | + let fixture = TestBed.createComponent(ComponentWithChildTextContent); |
| 41 | + fixture.detectChanges(); |
| 42 | + |
| 43 | + // If the hint label is empty, expect no label. |
| 44 | + const spy = spyOn(fixture.componentInstance, 'doSomething').and.callFake(() => { |
| 45 | + expect(spy.calls.any()).toBe(true); |
| 46 | + done(); |
| 47 | + }); |
| 48 | + |
| 49 | + expect(spy.calls.any()).toBe(false); |
| 50 | + |
| 51 | + fixture.componentInstance.text = 'text'; |
| 52 | + fixture.detectChanges(); |
| 53 | + }); |
| 54 | + }); |
| 55 | +}); |
| 56 | + |
| 57 | + |
| 58 | +@Component({ template: `<div (cdkObserveContent)="doSomething()">{{text}}</div>` }) |
| 59 | +class ComponentWithTextContent { |
| 60 | + text = ''; |
| 61 | + doSomething() {} |
| 62 | +} |
| 63 | + |
| 64 | +@Component({ template: `<div (cdkObserveContent)="doSomething()"><div>{{text}}<div></div>` }) |
| 65 | +class ComponentWithChildTextContent { |
| 66 | + text = ''; |
| 67 | + doSomething() {} |
| 68 | +} |
0 commit comments