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