Skip to content

Commit 14544e4

Browse files
authored
fix(api): avoid crashing in clearMocks, closes #8179 (#8219)
* fix(api): do nothing in clearMocks if __TAURI_INTERNALS__ is not defined (fix: #8179) Prevents tests that didn't define any mocks from failing in `afterEach` test hook. * Update fix-clearmocks.md * check for indvidiual properties instead
1 parent 1d5aa38 commit 14544e4

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

.changes/fix-clearmocks.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tauri-apps/api": 'patch:bug'
3+
---
4+
5+
Avoid crashing in `clearMocks`

tooling/api/src/mocks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ export function mockConvertFileSrc(
202202
*/
203203
export function clearMocks(): void {
204204
// @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
205-
delete window.__TAURI__.convertFileSrc
205+
if (window.__TAURI__?.convertFileSrc) delete window.__TAURI__.convertFileSrc
206206
// @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
207-
delete window.__TAURI_IPC__
207+
if (window.__TAURI_IPC__) delete window.__TAURI_IPC__
208208
// @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
209-
delete window.__TAURI_METADATA__
209+
if (window.__TAURI_METADATA__) delete window.__TAURI_METADATA__
210210
}

0 commit comments

Comments
 (0)