0

I have a component that takes NgZone as a provider. How can I make a provider for NgZone when creating the TestBed.

I tried this but the test is timing out

const mockNgZone = jasmine.createSpyObj('mockNgZone', ['run', 'runOutsideAngular'])
mockNgZone.run.and.callFake(fn => fn())

When I use this mockNgZone, the test is timing out with the error:

Disconnected (1 times), because no message in 10000 ms.
Electron 1.7.9 (Node 7.9.0) ERROR
   Disconnected, because no message in 10000 ms.
suku
  • 10,507
  • 16
  • 75
  • 120
  • 1
    mockNgZone.run.and.CallFake(function () {return something;});. The run and runOutsideAngular return value from the executed function. – notionquest Feb 06 '18 at 12:03
  • @notionquest, your answer worked. Can you write your comment as an answer? I'll mark it as correct also write the same answer here: https://stackoverflow.com/questions/47503064/running-jasmine-tests-for-a-component-with-ngzone-dependency – suku Feb 06 '18 at 12:10

1 Answers1

2

The run and runOutsideAngular methods of NgZone return value from the executed function. So, please return some value from the callFake function.

Example:-

mockNgZone.run.and.callFake(function () {return something;});
notionquest
  • 37,595
  • 6
  • 111
  • 105