Skip to content

Commit

Permalink
fix(api): avoid crashing in clearMocks, closes #8179 (#8219)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MGough committed Nov 13, 2023
1 parent 1d5aa38 commit 14544e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-clearmocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": 'patch:bug'
---

Avoid crashing in `clearMocks`
6 changes: 3 additions & 3 deletions tooling/api/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ export function mockConvertFileSrc(
*/
export function clearMocks(): void {
// @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
delete window.__TAURI__.convertFileSrc
if (window.__TAURI__?.convertFileSrc) delete window.__TAURI__.convertFileSrc
// @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
delete window.__TAURI_IPC__
if (window.__TAURI_IPC__) delete window.__TAURI_IPC__
// @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
delete window.__TAURI_METADATA__
if (window.__TAURI_METADATA__) delete window.__TAURI_METADATA__
}

0 comments on commit 14544e4

Please sign in to comment.