This is the archived documentation for Angular v6. Please visit angular.io to see documentation for the current version of Angular.

SpyLocation

A spy for Location that allows tests to fire simulated location events.

      
      class SpyLocation implements Location {
  urlChanges: string[]
  setInitialPath(url: string)
  setBaseHref(url: string)
  path(): string
  isCurrentPathEqualTo(path: string, query: string = ''): boolean
  simulateUrlPop(pathname: string)
  simulateHashChange(pathname: string)
  prepareExternalUrl(url: string): string
  go(path: string, query: string = '', state: any = null)
  replaceState(path: string, query: string = '', state: any = null)
  forward()
  back()
  subscribe(onNext: (value: any) => void, onThrow?: ((error: any) => void) | null, onReturn?: (() => void) | null): SubscriptionLike
  normalize(url: string): string
}
    

Properties

Property Description
urlChanges: string[]

Methods

setInitialPath(url: string)
      
      setInitialPath(url: string)
    

Parameters

url

Type: string.

setBaseHref(url: string)
      
      setBaseHref(url: string)
    

Parameters

url

Type: string.

path(): string
      
      path(): string
    

Parameters

There are no parameters.

Returns

string

isCurrentPathEqualTo(path: string, query: string = ''): boolean
      
      isCurrentPathEqualTo(path: string, query: string = ''): boolean
    

Parameters

path

Type: string.

query

Type: string.

Optional. Default is ''.

Returns

boolean

simulateUrlPop(pathname: string)
      
      simulateUrlPop(pathname: string)
    

Parameters

pathname

Type: string.

simulateHashChange(pathname: string)
      
      simulateHashChange(pathname: string)
    

Parameters

pathname

Type: string.

prepareExternalUrl(url: string): string
      
      prepareExternalUrl(url: string): string
    

Parameters

url

Type: string.

Returns

string

go(path: string, query: string = '', state: any = null)
      
      go(path: string, query: string = '', state: any = null)
    

Parameters

path

Type: string.

query

Type: string.

Optional. Default is ''.

state

Type: any.

Optional. Default is null.

replaceState(path: string, query: string = '', state: any = null)
      
      replaceState(path: string, query: string = '', state: any = null)
    

Parameters

path

Type: string.

query

Type: string.

Optional. Default is ''.

state

Type: any.

Optional. Default is null.

forward()
      
      forward()
    

Parameters

There are no parameters.

back()
      
      back()
    

Parameters

There are no parameters.

subscribe(onNext: (value: any) => void, onThrow?: ((error: any) => void) | null, onReturn?: (() => void) | null): SubscriptionLike
      
      subscribe(onNext: (value: any) => void, onThrow?: ((error: any) => void) | null, onReturn?: (() => void) | null): SubscriptionLike
    

Parameters

onNext

Type: (value: any) => void.

onThrow

Type: ((error: any) => void) | null.

Optional. Default is undefined.

onReturn

Type: (() => void) | null.

Optional. Default is undefined.

Returns

SubscriptionLike

normalize(url: string): string
      
      normalize(url: string): string
    

Parameters

url

Type: string.

Returns

string