@@ -23,11 +23,14 @@ describe('draggable directive', () => {
23
23
[ghostElementTemplate]="ghostElementTemplate"
24
24
(dragPointerDown)="dragPointerDown($event)"
25
25
(dragStart)="dragStart($event)"
26
+ (ghostElementCreated)="ghostElementCreated($event)"
26
27
(dragging)="dragging($event)"
27
28
(dragEnd)="dragEnd($event)">
28
29
Drag me!
29
30
</div>
30
- <ng-template #ghostElementTemplateRef><span>I'm being dragged!</span></ng-template>
31
+ <ng-template #ghostElementTemplateRef>
32
+ <span>{{ 1 + 1 }} test</span>
33
+ </ng-template>
31
34
`
32
35
} )
33
36
class TestComponent {
@@ -37,6 +40,7 @@ describe('draggable directive', () => {
37
40
ghostElementTemplateRef : TemplateRef < any > ;
38
41
dragPointerDown = sinon . spy ( ) ;
39
42
dragStart = sinon . spy ( ) ;
43
+ ghostElementCreated = sinon . spy ( ) ;
40
44
dragging = sinon . spy ( ) ;
41
45
dragEnd = sinon . spy ( ) ;
42
46
dragAxis : any = { x : true , y : true } ;
@@ -313,6 +317,8 @@ describe('draggable directive', () => {
313
317
triggerDomEvent ( 'mousedown' , draggableElement , { clientX : 5 , clientY : 10 } ) ;
314
318
triggerDomEvent ( 'mousemove' , draggableElement , { clientX : 7 , clientY : 10 } ) ;
315
319
expect ( fixture . componentInstance . dragStart ) . to . have . been . calledOnce ;
320
+ expect ( fixture . componentInstance . ghostElementCreated ) . not . to . have . been
321
+ . called ;
316
322
expect ( fixture . componentInstance . dragging ) . to . have . been . calledWith ( {
317
323
x : 2 ,
318
324
y : 0
@@ -563,7 +569,7 @@ describe('draggable directive', () => {
563
569
expect ( fixture . componentInstance . dragEnd ) . not . to . have . been . called ;
564
570
} ) ;
565
571
566
- it ( 'should call the drag start, dragging and end events in order' , ( ) => {
572
+ it ( 'should call the drag lifecycle events in order' , ( ) => {
567
573
const draggableElement =
568
574
fixture . componentInstance . draggableElement . nativeElement ;
569
575
triggerDomEvent ( 'mousedown' , draggableElement , { clientX : 5 , clientY : 10 } ) ;
@@ -572,6 +578,7 @@ describe('draggable directive', () => {
572
578
sinon . assert . callOrder (
573
579
fixture . componentInstance . dragPointerDown ,
574
580
fixture . componentInstance . dragStart ,
581
+ fixture . componentInstance . ghostElementCreated ,
575
582
fixture . componentInstance . dragging ,
576
583
fixture . componentInstance . dragEnd
577
584
) ;
@@ -712,7 +719,8 @@ describe('draggable directive', () => {
712
719
fixture . componentInstance . draggableElement . nativeElement ;
713
720
triggerDomEvent ( 'mousedown' , draggableElement , { clientX : 5 , clientY : 10 } ) ;
714
721
triggerDomEvent ( 'mousemove' , draggableElement , { clientX : 7 , clientY : 10 } ) ;
722
+ fixture . detectChanges ( ) ;
715
723
const ghostElement = draggableElement . nextSibling as HTMLElement ;
716
- expect ( ghostElement . innerHTML ) . to . equal ( " <span>I'm being dragged! </span>" ) ;
724
+ expect ( ghostElement . innerHTML ) . to . equal ( ' <span>2 test </span>' ) ;
717
725
} ) ;
718
726
} ) ;
0 commit comments