sync-test.js 987 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. /**
  3. * @license Angular v<unknown>
  4. * (c) 2010-2025 Google LLC. https://angular.io/
  5. * License: MIT
  6. */
  7. function patchSyncTest(Zone) {
  8. class SyncTestZoneSpec {
  9. runZone = Zone.current;
  10. constructor(namePrefix) {
  11. this.name = 'syncTestZone for ' + namePrefix;
  12. }
  13. // ZoneSpec implementation below.
  14. name;
  15. onScheduleTask(delegate, current, target, task) {
  16. switch (task.type) {
  17. case 'microTask':
  18. case 'macroTask':
  19. throw new Error(`Cannot call ${task.source} from within a sync test (${this.name}).`);
  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['SyncTestZoneSpec'] = SyncTestZoneSpec;
  30. }
  31. patchSyncTest(Zone);