sync-test.ts 931 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * @license
  3. * Copyright Google Inc. All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. class SyncTestZoneSpec implements ZoneSpec {
  9. runZone = Zone.current;
  10. constructor(namePrefix: string) {
  11. this.name = 'syncTestZone for ' + namePrefix;
  12. }
  13. // ZoneSpec implementation below.
  14. name: string;
  15. onScheduleTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task): Task {
  16. switch (task.type) {
  17. case 'microTask':
  18. case 'macroTask':
  19. throw new Error(`Cannot call ${task.source} from within a sync test.`);
  20. case 'eventTask':
  21. task = delegate.scheduleTask(target, task);
  22. break;
  23. }
  24. return task;
  25. }
  26. }
  27. // Export the class so that new instances can be created with proper
  28. // constructor params.
  29. (Zone as any)['SyncTestZoneSpec'] = SyncTestZoneSpec;