@@ -13,7 +13,7 @@ import {
1313 inject ,
1414 signal ,
1515} from '@angular/core' ;
16- import { ComponentFixture , fakeAsync , flush , TestBed , tick } from '@angular/core/testing' ;
16+ import { ComponentFixture , TestBed } from '@angular/core/testing' ;
1717import { Platform , _supportsShadowDom } from '../../platform' ;
1818import { CdkScrollable , ViewportRuler } from '../../scrolling' ;
1919import {
@@ -1096,19 +1096,19 @@ export function defineCommonDropListTests(config: {
10961096 . toBe ( sourceCanvas . toDataURL ( ) ) ;
10971097 } ) ;
10981098
1099- // TODO(crisbeto): this one is using `fakeAsync` because we throw an error from a subscription.
1100- it ( 'should not throw when cloning an invalid canvas' , fakeAsync ( ( ) => {
1101- const fixture = createComponent ( DraggableWithInvalidCanvasInDropZone ) ;
1102- fixture . detectChanges ( ) ;
1103- const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
1099+ it ( 'should not throw when cloning an invalid canvas' , async ( ) => {
1100+ await jasmine . spyOnGlobalErrorsAsync ( async globalErrorSpy => {
1101+ const fixture = createComponent ( DraggableWithInvalidCanvasInDropZone ) ;
1102+ fixture . detectChanges ( ) ;
1103+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
11041104
1105- expect ( ( ) => {
1106- startDraggingViaMouse ( fixture , item ) ;
1107- tick ( ) ;
1108- } ) . not . toThrow ( ) ;
1105+ expect ( ( ) => startDraggingViaMouse ( fixture , item ) ) . not . toThrow ( ) ;
1106+ await wait ( 0 ) ;
11091107
1110- expect ( document . querySelector ( '.cdk-drag-preview canvas' ) ) . toBeTruthy ( ) ;
1111- } ) ) ;
1108+ expect ( globalErrorSpy ) . not . toHaveBeenCalled ( ) ;
1109+ expect ( document . querySelector ( '.cdk-drag-preview canvas' ) ) . toBeTruthy ( ) ;
1110+ } ) ;
1111+ } ) ;
11121112
11131113 it ( 'should clone the content of descendant input elements' , ( ) => {
11141114 const fixture = createComponent ( DraggableWithInputsInDropZone ) ;
@@ -2340,29 +2340,32 @@ export function defineCommonDropListTests(config: {
23402340 ] ) ;
23412341 } ) ;
23422342
2343- // TODO(crisbeto): this one is using `fakeAsync` because we throw an error from a subscription.
2344- it ( 'should not throw if an item is removed after dragging has started' , fakeAsync ( ( ) => {
2345- const fixture = createComponent ( DraggableInDropZone ) ;
2346- fixture . detectChanges ( ) ;
2347- const dragItems = fixture . componentInstance . dragItems ;
2348- const firstElement = dragItems . first . element . nativeElement ;
2349- const lastItemRect = dragItems . last . element . nativeElement . getBoundingClientRect ( ) ;
2350-
2351- // Start dragging.
2352- startDraggingViaMouse ( fixture , firstElement ) ;
2343+ it ( 'should not throw if an item is removed after dragging has started' , async ( ) => {
2344+ await jasmine . spyOnGlobalErrorsAsync ( async globalErrorSpy => {
2345+ const fixture = createComponent ( DraggableInDropZone ) ;
2346+ fixture . detectChanges ( ) ;
2347+ const dragItems = fixture . componentInstance . dragItems ;
2348+ const firstElement = dragItems . first . element . nativeElement ;
2349+ const lastItemRect = dragItems . last . element . nativeElement . getBoundingClientRect ( ) ;
23532350
2354- // Remove the last item.
2355- fixture . componentInstance . items . pop ( ) ;
2356- fixture . changeDetectorRef . markForCheck ( ) ;
2357- fixture . detectChanges ( ) ;
2351+ // Start dragging.
2352+ startDraggingViaMouse ( fixture , firstElement ) ;
23582353
2359- expect ( ( ) => {
2360- // Move the dragged item over where the remove item would've been.
2361- dispatchMouseEvent ( document , 'mousemove' , lastItemRect . left + 1 , lastItemRect . top + 1 ) ;
2354+ // Remove the last item.
2355+ fixture . componentInstance . items . pop ( ) ;
2356+ fixture . changeDetectorRef . markForCheck ( ) ;
23622357 fixture . detectChanges ( ) ;
2363- flush ( ) ;
2364- } ) . not . toThrow ( ) ;
2365- } ) ) ;
2358+
2359+ expect ( ( ) => {
2360+ // Move the dragged item over where the remove item would've been.
2361+ dispatchMouseEvent ( document , 'mousemove' , lastItemRect . left + 1 , lastItemRect . top + 1 ) ;
2362+ fixture . detectChanges ( ) ;
2363+ } ) . not . toThrow ( ) ;
2364+ await wait ( 0 ) ;
2365+
2366+ expect ( globalErrorSpy ) . not . toHaveBeenCalled ( ) ;
2367+ } ) ;
2368+ } ) ;
23662369
23672370 it ( 'should not be able to start a drag sequence while another one is still active' , async ( ) => {
23682371 const fixture = createComponent ( DraggableInDropZone ) ;
@@ -4703,33 +4706,43 @@ export function defineCommonDropListTests(config: {
47034706 . toBe ( targetContainer ) ;
47044707 } ) ;
47054708
4706- // TODO(crisbeto): this one is using `fakeAsync` because we throw an error from a subscription.
4707- it ( 'should throw if the items are not inside of the alternate container' , fakeAsync ( ( ) => {
4708- const fixture = createComponent ( DraggableWithInvalidAlternateContainer ) ;
4709- fixture . detectChanges ( ) ;
4709+ it ( 'should throw if the items are not inside of the alternate container' , async ( ) => {
4710+ await jasmine . spyOnGlobalErrorsAsync ( async globalErrorSpy => {
4711+ const fixture = createComponent ( DraggableWithInvalidAlternateContainer ) ;
4712+ fixture . detectChanges ( ) ;
47104713
4711- expect ( ( ) => {
47124714 const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
47134715 startDraggingViaMouse ( fixture , item ) ;
4714- tick ( ) ;
4715- } ) . toThrowError (
4716- / I n v a l i d D O M s t r u c t u r e f o r d r o p l i s t \. A l l i t e m s m u s t b e p l a c e d d i r e c t l y i n s i d e o f t h e e l e m e n t c o n t a i n e r / ,
4717- ) ;
4718- } ) ) ;
4716+ await wait ( 0 ) ;
4717+
4718+ expect ( globalErrorSpy ) . toHaveBeenCalledWith (
4719+ jasmine . objectContaining ( {
4720+ message : jasmine . stringMatching (
4721+ / I n v a l i d D O M s t r u c t u r e f o r d r o p l i s t \. A l l i t e m s m u s t b e p l a c e d d i r e c t l y i n s i d e o f t h e e l e m e n t c o n t a i n e r / ,
4722+ ) ,
4723+ } ) ,
4724+ ) ;
4725+ } ) ;
4726+ } ) ;
47194727
4720- // TODO(crisbeto): this one is using `fakeAsync` because we throw an error from a subscription.
4721- it ( 'should throw if the alternate container cannot be found' , fakeAsync ( ( ) => {
4722- const fixture = createComponent ( DraggableWithMissingAlternateContainer ) ;
4723- fixture . detectChanges ( ) ;
4728+ it ( 'should throw if the alternate container cannot be found' , async ( ) => {
4729+ await jasmine . spyOnGlobalErrorsAsync ( async globalErrorSpy => {
4730+ const fixture = createComponent ( DraggableWithMissingAlternateContainer ) ;
4731+ fixture . detectChanges ( ) ;
47244732
4725- expect ( ( ) => {
47264733 const item = fixture . componentInstance . dragItems . first . element . nativeElement ;
47274734 startDraggingViaMouse ( fixture , item ) ;
4728- tick ( ) ;
4729- } ) . toThrowError (
4730- / C d k D r o p L i s t c o u l d n o t f i n d a n e l e m e n t c o n t a i n e r m a t c h i n g t h e s e l e c t o r " d o e s - n o t - e x i s t " / ,
4731- ) ;
4732- } ) ) ;
4735+ await wait ( 0 ) ;
4736+
4737+ expect ( globalErrorSpy ) . toHaveBeenCalledWith (
4738+ jasmine . objectContaining ( {
4739+ message : jasmine . stringMatching (
4740+ / C d k D r o p L i s t c o u l d n o t f i n d a n e l e m e n t c o n t a i n e r m a t c h i n g t h e s e l e c t o r " d o e s - n o t - e x i s t " / ,
4741+ ) ,
4742+ } ) ,
4743+ ) ;
4744+ } ) ;
4745+ } ) ;
47334746 } ) ;
47344747
47354748 describe ( 'with an anchor' , ( ) => {
0 commit comments