何时在angular中使用waitForAsync

问题描述

从文档中我们可以阅读:

waitForAsync(fn: Function): (done: any) => any

在异步测试区域中包装测试功能。测试将 当该区域内的所有异步调用自动完成 完成。可用于包装注入调用

我不明白,什么时候使用waitForAsync函数waitForAsync与(asyncfakeAsync)之间有什么区别?

解决方法

在Angular 10.1.0中,sparklyr取代了SparkDataFrame to avoid confusion,但在其他方面完全相同。您看到的使用waitForAsync()讨论的所有文档也将适用于async()async()已被标记为已弃用,并将在版本12中完全删除。

,

将测试功能包装在异步测试区域中。完成该区域内的所有异步调用后,测试将自动完成。可用于包装注入调用。

因此,您不必手动调用作为参数标记为测试已完成的fakeAsync()回调,也不必使用from '@angular/core/testing'和其他辅助功能it('...',waitForAsync(inject([AClass],(object) => { object.doSomething.then(() => { expect(...); }) });

@echo off
setlocal EnableExtensions DisableDelayedExpansion
title User prompt demo
cls

:GetName
rem Undefine the environment variable Name.
set "Name="

rem Prompt the user for the name.
set /P "Name=What is your name? "

rem Has the user just pressed RETURN or ENTER without entering a string?
if not defined Name goto GetName

rem Remove all double quotes from user input string.
set "Name=%Name:"=%"

rem Has the user entered just double quotes?
if not defined Name goto GetName

rem Output an empty line.
echo/

rem Enable delayed expansion and output the input string which could
rem contain characters like ampersands,angle brackets or pipes which
rem would modify the command line with ECHO before execution on not
rem using delayed environment variable expansion. The exclamation mark
rem at end must be escaped twice with caret character to be interpreted
rem as literal character to print by command ECHO in this case. Then
rem restore the previous execution environment as defined at top.
setlocal EnableDelayedExpansion
echo Hello !Name!^^!
endlocal

echo/
echo inserted text here
echo inserted text here
echo inserted text here
echo inserted text here
echo inserted text here
echo/

rem A classic yes/no prompt is done best with using command CHOICE which
rem is by default available since Windows Vista and Windows Server 2003.
%SystemRoot%\System32\choice.exe /C YN /N /M "What is the password,yes or no? (Y,N):"
if errorlevel 2 exit /B

rem The user pressed key Y and so the batch file processing continues.
echo/
echo Secret file: %UserProfile%\Desktop\name\files
endlocal

请参见docs