Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 16be7f9

Browse files
marclavalmhevery
authored andcommitted
fix: make fetch promise patching safe
Closes #451
1 parent a85db4c commit 16be7f9

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = function (config) {
66
files: [
77
'node_modules/systemjs/dist/system-polyfills.js',
88
'node_modules/systemjs/dist/system.src.js',
9+
'node_modules/whatwg-fetch/fetch.js',
910
{pattern: 'test/assets/**/*.*', watched: true, served: true, included: false},
1011
{pattern: 'build/**/*.js.map', watched: true, served: true, included: false},
1112
{pattern: 'build/**/*.js', watched: true, served: true, included: false},

lib/zone.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ const Zone: ZoneType = (function(global: any) {
11551155
}
11561156
// ignore output to prevent error;
11571157
fetchPromise.then(() => null, () => null);
1158-
if (fetchPromise.constructor != NativePromise) {
1158+
if (fetchPromise.constructor != NativePromise && fetchPromise.constructor != ZoneAwarePromise) {
11591159
patchThen(fetchPromise.constructor);
11601160
}
11611161
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@types/systemjs": "^0.19.30",
3939
"concurrently": "^2.2.0",
4040
"es6-promise": "^3.0.2",
41+
"whatwg-fetch": "^1.0.0",
4142
"gulp": "^3.8.11",
4243
"gulp-rename": "^1.2.2",
4344
"gulp-rollup": "^2.3.0",

test/common/Promise.spec.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,22 @@ describe('Promise', ifEnvSupports('Promise', function () {
341341
});
342342
});
343343

344-
it('should work for blob response', function(done) {
345-
testZone.run(function() {
346-
global['fetch']('/base/test/assets/sample.json').then(function(response: any) {
344+
it('should work for blob response', function (done) {
345+
testZone.run(function () {
346+
global['fetch']('/base/test/assets/sample.json').then(function (response:any) {
347347
var fetchZone = Zone.current;
348348
expect(fetchZone).toBe(testZone);
349349

350-
response.blob().then(function(blob) {
351-
expect(Zone.current).toBe(fetchZone);
352-
expect(blob instanceof Blob).toEqual(true);
350+
// Android 4.3- doesn't support response.blob()
351+
if (response.blob) {
352+
response.blob().then(function (blob) {
353+
expect(Zone.current).toBe(fetchZone);
354+
expect(blob instanceof Blob).toEqual(true);
355+
done();
356+
});
357+
} else {
353358
done();
354-
});
359+
}
355360
});
356361
});
357362
});
@@ -362,13 +367,19 @@ describe('Promise', ifEnvSupports('Promise', function () {
362367
var fetchZone = Zone.current;
363368
expect(fetchZone).toBe(testZone);
364369

365-
response.arrayBuffer().then(function(blob) {
366-
expect(Zone.current).toBe(fetchZone);
367-
expect(blob instanceof ArrayBuffer).toEqual(true);
370+
// Android 4.3- doesn't support response.arrayBuffer()
371+
if (response.arrayBuffer) {
372+
response.arrayBuffer().then(function (blob) {
373+
expect(Zone.current).toBe(fetchZone);
374+
expect(blob instanceof ArrayBuffer).toEqual(true);
375+
done();
376+
});
377+
} else {
368378
done();
369-
});
379+
}
370380
});
371381
});
372382
});
383+
373384
}));
374385
}));

0 commit comments

Comments
 (0)