ng test failure: 'Error: Cannot call Promise.then from within a sync test'

1,691 views
Skip to first unread message

Matthew Hegarty

unread,
Sep 19, 2016, 4:04:12 PM9/19/16
to AngularJS
Hi All

I'm new to Angular2 and am struggling with the basics.  I have a simple component and I thought it would be sensible to write a unit test.  I followed the Twain example which is very similar to what I am trying to achieve.
The issue is that whenever I include my test spec I see the error:

Chromium 52.0.2743 (Ubuntu 0.0.0) ClientLogoCarouselComponent encountered a declaration exception FAILED
Error: Cannot call Promise.then from within a sync test.
   at SyncTestZoneSpec.onScheduleTask (webpack:///home/matthew/Projects/cf/~/zone.js/dist/sync-test.js:11:0 <- src/test.ts:24070:27)
   at ZoneDelegate.scheduleTask (webpack:///home/matthew/Projects/cf/~/zone.js/dist/zone.js:202:0 <- src/test.ts:46485:49)
   at Zone.scheduleMicroTask (webpack:///home/matthew/Projects/cf/~/zone.js/dist/zone.js:139:0 <- src/test.ts:46422:39)
   at scheduleResolveOrReject (webpack:///home/matthew/Projects/cf/~/zone.js/dist/zone.js:449:0 <- src/test.ts:46732:14)
   at ZoneAwarePromise.then (webpack:///home/matthew/Projects/cf/~/zone.js/dist/zone.js:525:0 <- src/test.ts:46808:17)
   at new ApplicationInitStatus (webpack:///home/matthew/Projects/cf/~/@angular/core/src/application_init.js:33:0 <- src/test.ts:9491:60)
   at NgModuleInjector.DynamicTestModuleInjector.createInternal (DynamicTestModule.ngfactory.js:133:36)
   at NgModuleInjector.create (webpack:///home/matthew/Projects/cf/~/@angular/core/src/linker/ng_module_factory.js:88:53 <- src/test.ts:17465:76)
   at NgModuleFactory.create (webpack:///home/matthew/Projects/cf/~/@angular/core/src/linker/ng_module_factory.js:73:0 <- src/test.ts:17450:18)
   at TestBed._initIfNeeded (webpack:///home/matthew/Projects/cf/~/@angular/core/bundles/core-testing.umd.js:1072:0 <- src/test.ts:5230:68)

I have setup my new project with Angular cli (1.0.0-beta.14; node: 6.4.0).  I run the test suite with 'ng test'

If I comment out 'client-logo-carousel.component.spec.ts' then the Twain test example runs fine in my project.

The stacktrace refers to test.ts which must somehow be the source of the problem.  I've included that in the plunkr.  I am stuck here so I hope someone can offer some guidance.

The code for the component is here:  http://embed.plnkr.co/vva6F8mzm10LMM2aGrHb/

Thanks
Matt
Reply all
Reply to author
Forward
0 new messages