Skip to content

Commit

Permalink
fix(core): fix angular#1153, ZoneTask.toString should always be a string
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Nov 21, 2018
1 parent 9ed5712 commit 78ffe47
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ const Zone: ZoneType = (function(global: any) {

public toString() {
if (this.data && typeof this.data.handleId !== 'undefined') {
return this.data.handleId;
return this.data.handleId.toString();
} else {
return Object.prototype.toString.call(this);
}
Expand Down
36 changes: 36 additions & 0 deletions test/common/toString.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,39 @@ describe('global function patch', () => {
}));
});
});

describe('ZoneTask', () => {
it('should return handleId.toString if handleId is available', () => {
let macroTask1: any = undefined;
let macroTask2: any = undefined;
let microTask: any = undefined;
const zone = Zone.current.fork({
name: 'timer',
onScheduleTask: (delegate: ZoneDelegate, curr: Zone, target: Zone, task: Task) => {
if (task.type === 'macroTask') {
if (!macroTask1) {
macroTask1 = task;
} else {
macroTask2 = task;
}
} else if (task.type === 'microTask') {
microTask = task;
}
return task;
}
});
zone.run(() => {
const id1 = setTimeout(() => {});
clearTimeout(id1);
const id2 = setTimeout(() => {});
clearTimeout(id2);
Promise.resolve().then(() => {});
expect(typeof macroTask1.toString()).toEqual('string');
expect(macroTask1.toString()).toEqual(id1.toString());
expect(typeof macroTask2.toString()).toEqual('string');
expect(macroTask2.toString()).toEqual(id2.toString());
expect(macroTask1.toString()).not.toEqual(macroTask2.toString());
expect(typeof microTask.toString()).toEqual('string');
});
});
});

0 comments on commit 78ffe47

Please sign in to comment.