Testability

The Testability service provides testing hooks that can be accessed from the browser and by services such as Protractor. Each bootstrapped Angular application on the page will have an instance of Testability.

      
      class Testability implements PublicTestability {
  increasePendingRequestCount(): number
  decreasePendingRequestCount(): number
  isStable(): boolean
  whenStable(doneCb: Function, timeout?: number, updateCb?: Function): void
  getPendingRequestCount(): number
  findProviders(using: any, provider: string, exactMatch: boolean): any[]
}
    

方法

Increases the number of pending request

increasePendingRequestCount(): number
      
      increasePendingRequestCount(): number
    

Deprecated pending requests are now tracked with zones.

参数

没有参数。

返回值

number

Decreases the number of pending request

decreasePendingRequestCount(): number
      
      decreasePendingRequestCount(): number
    

Deprecated pending requests are now tracked with zones

参数

没有参数。

返回值

number

Whether an associated application is stable

isStable(): boolean
      
      isStable(): boolean
    
参数

没有参数。

返回值

boolean

Wait for the application to be stable with a timeout. If the timeout is reached before that happens, the callback receives a list of the macro tasks that were pending, otherwise null.

whenStable(doneCb: Function, timeout?: number, updateCb?: Function): void
      
      whenStable(doneCb: Function, timeout?: number, updateCb?: Function): void
    
参数
doneCb Function

The callback to invoke when Angular is stable or the timeout expires whichever comes first.

timeout number

可选. 默认值是 undefined.

Optional. The maximum time to wait for Angular to become stable. If not specified, whenStable() will wait forever.

updateCb Function

可选. 默认值是 undefined.

Optional. If specified, this callback will be invoked whenever the set of pending macrotasks changes. If this callback returns true doneCb will not be invoked and no further updates will be issued.

返回值

void

Get the number of pending requests

getPendingRequestCount(): number
      
      getPendingRequestCount(): number
    

Deprecated pending requests are now tracked with zones

参数

没有参数。

返回值

number

Find providers by name

findProviders(using: any, provider: string, exactMatch: boolean): any[]
      
      findProviders(using: any, provider: string, exactMatch: boolean): any[]
    
参数
using any

The root element to search from

provider string

The name of binding variable

exactMatch boolean

Whether using exactMatch

返回值

any[]