sync-test.js 940 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. /**
  3. * @license Angular v<unknown>
  4. * (c) 2010-2024 Google LLC. https://angular.io/
  5. * License: MIT
  6. */
  7. function patchSyncTest(Zone) {
  8. class SyncTestZoneSpec {
  9. constructor(namePrefix) {
  10. this.runZone = Zone.current;
  11. this.name = 'syncTestZone for ' + namePrefix;
  12. }
  13. onScheduleTask(delegate, current, target, task) {
  14. switch (task.type) {
  15. case 'microTask':
  16. case 'macroTask':
  17. throw new Error(`Cannot call ${task.source} from within a sync test (${this.name}).`);
  18. case 'eventTask':
  19. task = delegate.scheduleTask(target, task);
  20. break;
  21. }
  22. return task;
  23. }
  24. }
  25. // Export the class so that new instances can be created with proper
  26. // constructor params.
  27. Zone['SyncTestZoneSpec'] = SyncTestZoneSpec;
  28. }
  29. patchSyncTest(Zone);