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.

MockLocationStrategy

A mock implementation of LocationStrategy that allows tests to fire simulated location events.

      
      class MockLocationStrategy extends LocationStrategy {
  internalBaseHref: string
  internalPath: string
  internalTitle: string
  urlChanges: string[]
simulatePopState(url: string): void
path(includeHash: boolean = false): string
prepareExternalUrl(internal: string): string
pushState(ctx: any, title: string, path: string, query: string): void
replaceState(ctx: any, title: string, path: string, query: string): void
onPopState(fn: (value: any) => void): void
getBaseHref(): string
back(): void
forward(): void
getState(): unknown // inherited from common/LocationStrategy
abstract path(includeHash?: boolean): string
abstract prepareExternalUrl(internal: string): string
abstract getState(): unknown
abstract pushState(state: any, title: string, url: string, queryParams: string): void
abstract replaceState(state: any, title: string, url: string, queryParams: string): void
abstract forward(): void
abstract back(): void
historyGo(relativePosition: number)?: void
abstract onPopState(fn: LocationChangeListener): void
abstract getBaseHref(): string }

Properties

Property Description
internalBaseHref: string
internalPath: string
internalTitle: string
urlChanges: string[]

Methods

      
      simulatePopState(url: string): void
    
Parameters
url string
Returns

void

      
      path(includeHash: boolean = false): string
    
Parameters
includeHash boolean

Optional. Default is false.

Returns

string

      
      prepareExternalUrl(internal: string): string
    
Parameters
internal string
Returns

string

      
      pushState(ctx: any, title: string, path: string, query: string): void
    
Parameters
ctx any
title string
path string
query string
Returns

void

      
      replaceState(ctx: any, title: string, path: string, query: string): void
    
Parameters
ctx any
title string
path string
query string
Returns

void

      
      onPopState(fn: (value: any) => void): void
    
Parameters
fn (value: any) => void
Returns

void

      
      getBaseHref(): string
    
Parameters

There are no parameters.

Returns

string

      
      back(): void
    
Parameters

There are no parameters.

Returns

void

      
      forward(): void
    
Parameters

There are no parameters.

Returns

void

      
      getState(): unknown
    
Parameters

There are no parameters.

Returns

unknown