Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page 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
getState(): unknown
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()
historyGo(relativePosition: number = 0): void
onUrlChange(fn: (url: string, state: unknown) => void): VoidFunction
subscribe(onNext: (value: any) => void, onThrow?: (error: any) => void, onReturn?: () => void): SubscriptionLike
normalize(url: string): string }

Properties

Property Description
urlChanges: string[]

Methods

      
      setInitialPath(url: string)
    
Parameters
url string
      
      setBaseHref(url: string)
    
Parameters
url string
      
      path(): string
    
Parameters

There are no parameters.

Returns

string

      
      getState(): unknown
    
Parameters

There are no parameters.

Returns

unknown

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

Optional. Default is ''.

Returns

boolean

      
      simulateUrlPop(pathname: string)
    
Parameters
pathname string
      
      simulateHashChange(pathname: string)
    
Parameters
pathname string
      
      prepareExternalUrl(url: string): string
    
Parameters
url string
Returns

string

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

Optional. Default is ''.

state any

Optional. Default is null.

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

Optional. Default is ''.

state any

Optional. Default is null.

      
      forward()
    
Parameters

There are no parameters.

      
      back()
    
Parameters

There are no parameters.

      
      historyGo(relativePosition: number = 0): void
    
Parameters
relativePosition number

Optional. Default is 0.

Returns

void

      
      onUrlChange(fn: (url: string, state: unknown) => void): VoidFunction
    
Parameters
fn (url: string, state: unknown) => void
Returns

VoidFunction

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

Optional. Default is undefined.

onReturn () => void

Optional. Default is undefined.

Returns

SubscriptionLike

      
      normalize(url: string): string
    
Parameters
url string
Returns

string