This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 408
fix(core): fix #1153, ZoneTask.toString should always be a string #1166
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,43 @@ 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(() => {}); | ||
const macroTask1Str = macroTask1.toString(); | ||
const macroTask2Str = macroTask2.toString(); | ||
expect(typeof macroTask1Str).toEqual('string'); | ||
expect(macroTask1Str).toEqual(id1.toString()); | ||
expect(typeof macroTask2Str).toEqual('string'); | ||
expect(macroTask2Str).toEqual(id2.toString()); | ||
if (macroTask1.data && typeof macroTask1.data.handleId === 'number') { | ||
expect(macroTask1Str).not.toEqual(macroTask2Str); | ||
} | ||
expect(typeof microTask.toString()).toEqual('string'); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be valueable to also verify that two different macrotasks have different string representations (just in case). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, case added. |
||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this check necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the reason is this case will also run in
nodejs
environment, innodejs
thehandleId
will be aTimerObject
, in that case, we will not check their equality.