-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ππ move stubZoneJs in its own module
- Loading branch information
1 parent
669b1ec
commit 25b3365
Showing
5 changed files
with
32 additions
and
32 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
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,29 @@ | ||
import type { BrowserWindowWithZoneJs } from '../src/tools/getZoneJsOriginalValue' | ||
|
||
export function stubZoneJs() { | ||
const browserWindow = window as BrowserWindowWithZoneJs | ||
const restorers: Array<() => void> = [] | ||
|
||
function getSymbol(name: string) { | ||
return `__zone_symbol__${name}` | ||
} | ||
|
||
browserWindow.Zone = { __symbol__: getSymbol } | ||
|
||
return { | ||
restore: () => { | ||
delete browserWindow.Zone | ||
restorers.forEach((restorer) => restorer()) | ||
}, | ||
getSymbol, | ||
replaceProperty<Target, Name extends keyof Target & string>(target: Target, name: Name, replacement: Target[Name]) { | ||
const original = target[name] | ||
target[name] = replacement | ||
;(target as any)[getSymbol(name)] = original | ||
restorers.push(() => { | ||
delete (target as any)[getSymbol(name)] | ||
target[name] = original | ||
}) | ||
}, | ||
} | ||
} |
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