docs: edit copy for tick() in testing and api docs (#35697)
Fixes #35696 PR Close #35697
This commit is contained in:
		
							parent
							
								
									594e63315e
								
							
						
					
					
						commit
						d7768c61ad
					
				| @ -26,21 +26,25 @@ export function resetFakeAsyncZone(): void { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Wraps a function to be executed in the fakeAsync zone: |  * Wraps a function to be executed in the `fakeAsync` zone: | ||||||
|  * - microtasks are manually executed by calling `flushMicrotasks()`, |  * - Microtasks are manually executed by calling `flushMicrotasks()`. | ||||||
|  * - timers are synchronous, `tick()` simulates the asynchronous passage of time. |  * - Timers are synchronous; `tick()` simulates the asynchronous passage of time. | ||||||
|  * |  * | ||||||
|  * If there are any pending timers at the end of the function, an exception will be thrown. |  * If there are any pending timers at the end of the function, an exception is thrown. | ||||||
|  * |  * | ||||||
|  * Can be used to wrap inject() calls. |  * Can be used to wrap `inject()` calls. | ||||||
|  |  * | ||||||
|  |  * @param fn The function that you want to wrap in the `fakeAysnc` zone. | ||||||
|  * |  * | ||||||
|  * @usageNotes |  * @usageNotes | ||||||
|  * ### Example |  * ### Example | ||||||
|  * |  * | ||||||
|  * {@example core/testing/ts/fake_async.ts region='basic'} |  * {@example core/testing/ts/fake_async.ts region='basic'} | ||||||
|  * |  * | ||||||
|  * @param fn |  * | ||||||
|  * @returns The function wrapped to be executed in the fakeAsync zone |  * @returns The function wrapped to be executed in the `fakeAsync` zone. | ||||||
|  |  * Any arguments passed when calling this returned function will be passed through to the `fn` | ||||||
|  |  * function in the parameters when it is called. | ||||||
|  * |  * | ||||||
|  * @publicApi |  * @publicApi | ||||||
|  */ |  */ | ||||||
| @ -52,23 +56,36 @@ export function fakeAsync(fn: Function): (...args: any[]) => any { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Simulates the asynchronous passage of time for the timers in the fakeAsync zone. |  * Simulates the asynchronous passage of time for the timers in the `fakeAsync` zone. | ||||||
|  * |  * | ||||||
|  * The microtasks queue is drained at the very start of this function and after any timer callback |  * The microtasks queue is drained at the very start of this function and after any timer callback | ||||||
|  * has been executed. |  * has been executed. | ||||||
|  * |  * | ||||||
|  |  * @param millis The number of milliseconds to advance the virtual timer. | ||||||
|  |  * @param tickOptions The options to pass to the `tick()` function. | ||||||
|  |  * | ||||||
|  * @usageNotes |  * @usageNotes | ||||||
|  |  * | ||||||
|  |  * The `tick()` option is a flag called `processNewMacroTasksSynchronously`, | ||||||
|  |  * which determines whether or not to invoke new macroTasks. | ||||||
|  |  * | ||||||
|  |  * If you provide a `tickOptions` object, but do not specify a | ||||||
|  |  * `processNewMacroTasksSynchronously` property (`tick(100, {})`), | ||||||
|  |  * then `processNewMacroTasksSynchronously` defaults to true. | ||||||
|  |  * | ||||||
|  |  * If you omit the `tickOptions` parameter (`tick(100))`), then | ||||||
|  |  * `tickOptions` defaults to `{processNewMacroTasksSynchronously: true}`. | ||||||
|  |  * | ||||||
|  * ### Example |  * ### Example | ||||||
|  * |  * | ||||||
|  * {@example core/testing/ts/fake_async.ts region='basic'} |  * {@example core/testing/ts/fake_async.ts region='basic'} | ||||||
|  * |  * | ||||||
|  * @param millis, the number of millisecond to advance the virtual timer |  * The following example includes a nested timeout (new macroTask), and | ||||||
|  * @param tickOptions, the options of tick with a flag called |  * the `tickOptions` parameter is allowed to default. In this case, | ||||||
|  * processNewMacroTasksSynchronously, whether to invoke the new macroTasks, by default is |  * `processNewMacroTasksSynchronously` defaults to true, and the nested | ||||||
|  * false, means the new macroTasks will be invoked |  * function is executed on each tick. | ||||||
|  * |  | ||||||
|  * For example, |  | ||||||
|  * |  * | ||||||
|  |  * ``` | ||||||
|  * it ('test with nested setTimeout', fakeAsync(() => { |  * it ('test with nested setTimeout', fakeAsync(() => { | ||||||
|  *   let nestedTimeoutInvoked = false; |  *   let nestedTimeoutInvoked = false; | ||||||
|  *   function funcWithNestedTimeout() { |  *   function funcWithNestedTimeout() { | ||||||
| @ -80,10 +97,12 @@ export function fakeAsync(fn: Function): (...args: any[]) => any { | |||||||
|  *   tick(); |  *   tick(); | ||||||
|  *   expect(nestedTimeoutInvoked).toBe(true); |  *   expect(nestedTimeoutInvoked).toBe(true); | ||||||
|  * })); |  * })); | ||||||
|  |  * ``` | ||||||
|  * |  * | ||||||
|  * in this case, we have a nested timeout (new macroTask), when we tick, both the |  * In the following case, `processNewMacroTasksSynchronously` is explicitly | ||||||
|  * funcWithNestedTimeout and the nested timeout both will be invoked. |  * set to false, so the nested timeout function is not invoked. | ||||||
|  * |  * | ||||||
|  |  * ``` | ||||||
|  * it ('test with nested setTimeout', fakeAsync(() => { |  * it ('test with nested setTimeout', fakeAsync(() => { | ||||||
|  *   let nestedTimeoutInvoked = false; |  *   let nestedTimeoutInvoked = false; | ||||||
|  *   function funcWithNestedTimeout() { |  *   function funcWithNestedTimeout() { | ||||||
| @ -95,9 +114,7 @@ export function fakeAsync(fn: Function): (...args: any[]) => any { | |||||||
|  *   tick(0, {processNewMacroTasksSynchronously: false}); |  *   tick(0, {processNewMacroTasksSynchronously: false}); | ||||||
|  *   expect(nestedTimeoutInvoked).toBe(false); |  *   expect(nestedTimeoutInvoked).toBe(false); | ||||||
|  * })); |  * })); | ||||||
|  * |  * ``` | ||||||
|  * if we pass the tickOptions with processNewMacroTasksSynchronously to be false, the nested timeout |  | ||||||
|  * will not be invoked. |  | ||||||
|  * |  * | ||||||
|  * |  * | ||||||
|  * @publicApi |  * @publicApi | ||||||
| @ -113,12 +130,12 @@ export function tick( | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Simulates the asynchronous passage of time for the timers in the fakeAsync zone by |  * Simulates the asynchronous passage of time for the timers in the `fakeAsync` zone by | ||||||
|  * draining the macrotask queue until it is empty. The returned value is the milliseconds |  * draining the macrotask queue until it is empty. | ||||||
|  * of time that would have been elapsed. |  | ||||||
|  * |  * | ||||||
|  * @param maxTurns |  * @param maxTurns The maximum number of times the scheduler attempts to clear its queue before | ||||||
|  * @returns The simulated time elapsed, in millis. |  *     throwing an error. | ||||||
|  |  * @returns The simulated time elapsed, in milliseconds. | ||||||
|  * |  * | ||||||
|  * @publicApi |  * @publicApi | ||||||
|  */ |  */ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user