mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
fix(api): do nothing in clearMocks if __TAURI_INTERNALS__ is not defined (#8071)
This commit is contained in:
committed by
GitHub
parent
c6c59cf237
commit
287066b279
5
.changes/fix-clearmocks.md
Normal file
5
.changes/fix-clearmocks.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@tauri-apps/api": 'patch:bug'
|
||||
---
|
||||
|
||||
No longer crashing in tests without mocks when `clearMocks` is defined in `afterEach` hook.
|
||||
@@ -152,11 +152,12 @@ export function mockWindows(
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
export function mockConvertFileSrc(
|
||||
osName: string
|
||||
): void {
|
||||
export function mockConvertFileSrc(osName: string): void {
|
||||
window.__TAURI_INTERNALS__ = window.__TAURI_INTERNALS__ ?? {}
|
||||
window.__TAURI_INTERNALS__.convertFileSrc = function (filePath, protocol = 'asset') {
|
||||
window.__TAURI_INTERNALS__.convertFileSrc = function (
|
||||
filePath,
|
||||
protocol = 'asset'
|
||||
) {
|
||||
const path = encodeURIComponent(filePath)
|
||||
return osName === 'windows'
|
||||
? `http://${protocol}.localhost/${path}`
|
||||
@@ -191,6 +192,10 @@ export function mockConvertFileSrc(
|
||||
* @since 1.0.0
|
||||
*/
|
||||
export function clearMocks(): void {
|
||||
if (typeof window.__TAURI_INTERNALS__ !== 'object') {
|
||||
return
|
||||
}
|
||||
|
||||
// @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
|
||||
delete window.__TAURI_INTERNALS__.convertFileSrc
|
||||
// @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
|
||||
|
||||
Reference in New Issue
Block a user