This repository has been archived by the owner on May 29, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: provide typesafe mocks for `SSR_USER_AGENT` & `SSR_LOCATION` * chore: move mock-fallbacks (for user-agent & location) to another places
- Loading branch information
1 parent
df7569c
commit ee98d1b
Showing
7 changed files
with
49 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class DOMStringListMock extends Array<string> implements DOMStringList { | ||
contains(): boolean { | ||
return false; | ||
} | ||
|
||
item(): null { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {emptyFunction} from '../utils/functions'; | ||
import {DOMStringListMock} from './dom-string-list-mock'; | ||
|
||
export class LocationMock implements Location { | ||
readonly ancestorOrigins = new DOMStringListMock(); | ||
hash = ''; | ||
host = ''; | ||
hostname = ''; | ||
href = ''; | ||
readonly origin = ''; | ||
pathname = ''; | ||
port = ''; | ||
protocol = ''; | ||
search = ''; | ||
|
||
assign = emptyFunction; | ||
|
||
reload = emptyFunction; | ||
|
||
replace = emptyFunction; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import {FactoryProvider} from '@angular/core'; | ||
import {FactoryProvider, Optional} from '@angular/core'; | ||
import {LOCATION} from '@ng-web-apis/common'; | ||
|
||
import {LocationMock} from '../classes/location-mock'; | ||
import {SSR_LOCATION} from '../tokens/ssr-location'; | ||
import {identity} from '../utils/functions'; | ||
|
||
export const UNIVERSAL_LOCATION: FactoryProvider = { | ||
provide: LOCATION, | ||
deps: [SSR_LOCATION], | ||
useFactory: identity, | ||
deps: [[new Optional(), SSR_LOCATION]], | ||
useFactory: (location: Location | null) => location || new LocationMock(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import {FactoryProvider} from '@angular/core'; | ||
import {FactoryProvider, Optional} from '@angular/core'; | ||
import {USER_AGENT} from '@ng-web-apis/common'; | ||
|
||
import {SSR_USER_AGENT} from '../tokens/ssr-user-agent'; | ||
import {identity} from '../utils/functions'; | ||
|
||
export const UNIVERSAL_USER_AGENT: FactoryProvider = { | ||
provide: USER_AGENT, | ||
deps: [SSR_USER_AGENT], | ||
useFactory: identity, | ||
deps: [[new Optional(), SSR_USER_AGENT]], | ||
useFactory: (userAgent: string | null) => userAgent || '', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters