Skip to content

Commit

Permalink
test: update tests to not run jasmine done function in sync-test zo…
Browse files Browse the repository at this point in the history
…ne from `describe` block

There are some ZoneJS tests that fork the zone from the `describe` block
for testing the zone patching. This does cause the Jasmine `done`
function later in `it` specs to be invoked in the sync-test zone from
the original `describe` block. The `done` implementation now has
changed with the Karma Jasmine update and breaks because it now causes
tasks to be scheduled.

It is conceptually incorrect/invalid to take the describe sync zone and
run test logic with that sync zone.

```
 An error was thrown in afterAll
  error properties: Object({ originalStack: 'Error: Cannot call jasmine.execute().forceTask from within a sync test (syncTestZone for jasmine.describe#FileReader).
      at new ZoneAwareError (packages/zone.js/test/browser_test_rollup.umd.js:98:37)
      at e.onScheduleTask (packages/zone.js/bundles/zone-testing-bundle.umd.min.js:158:196)
      at e.scheduleTask (packages/zone.js/bundles/zone-testing-bundle.umd.min.js:14:7529)
      at t.scheduleTask (packages/zone.js/bundles/zone-testing-bundle.umd.min.js:14:3539)
      at t.scheduleMicroTask (packages/zone.js/bundles/zone-testing-bundle.umd.min.js:14:3791)
      at r.execute (packages/zone.js/bundles/zone-testing-bundle.umd.min.js:166:4312)
      at queueRunnerFa ...
      at <Jasmine>
```
  • Loading branch information
devversion committed Jul 18, 2022
1 parent 6c08635 commit 5004b6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/zone.js/test/browser/FileReader.spec.ts
Expand Up @@ -13,7 +13,6 @@ describe('FileReader', ifEnvSupports('FileReader', function() {
let fileReader: FileReader;
let blob: Blob;
const data = 'Hello, World!';
const testZone = Zone.current.fork({name: 'TestZone'});

// Android 4.3's native browser doesn't implement add/RemoveEventListener for FileReader
function supportsEventTargetFns() {
Expand All @@ -39,6 +38,8 @@ describe('FileReader', ifEnvSupports('FileReader', function() {

describe('EventTarget methods', ifEnvSupports(supportsEventTargetFns, function() {
it('should bind addEventListener listeners', function(done) {
const testZone = Zone.current.fork({name: 'TestZone'});

testZone.run(function() {
fileReader.addEventListener('load', function() {
expect(Zone.current).toBe(testZone);
Expand All @@ -51,6 +52,7 @@ describe('FileReader', ifEnvSupports('FileReader', function() {
});

it('should remove listeners via removeEventListener', function(done) {
const testZone = Zone.current.fork({name: 'TestZone'});
const listenerSpy = jasmine.createSpy('listener');

testZone.run(function() {
Expand All @@ -67,6 +69,7 @@ describe('FileReader', ifEnvSupports('FileReader', function() {
}));

it('should bind onEventType listeners', function(done) {
const testZone = Zone.current.fork({name: 'TestZone'});
let listenersCalled = 0;

testZone.run(function() {
Expand Down
5 changes: 2 additions & 3 deletions packages/zone.js/test/browser/MutationObserver.spec.ts
Expand Up @@ -12,13 +12,13 @@ declare const global: any;

describe('MutationObserver', ifEnvSupports('MutationObserver', function() {
let elt: HTMLDivElement;
const testZone = Zone.current.fork({name: 'test'});

beforeEach(function() {
elt = document.createElement('div');
});

it('should run observers within the zone', function(done) {
const testZone = Zone.current.fork({name: 'test'});
let ob;

testZone.run(function() {
Expand Down Expand Up @@ -54,9 +54,8 @@ describe('MutationObserver', ifEnvSupports('MutationObserver', function() {
}));

describe('WebKitMutationObserver', ifEnvSupports('WebKitMutationObserver', function() {
const testZone = Zone.current.fork({name: 'test'});

it('should run observers within the zone', function(done) {
const testZone = Zone.current.fork({name: 'test'});
let elt: HTMLDivElement;

testZone.run(function() {
Expand Down

0 comments on commit 5004b6e

Please sign in to comment.