Repository: tauri-apps/tauri
File: packages/api/src/mocks.ts (TypeScript)

Code before:
 * ```js
 * import { mockWindows, clearMocks } from "@tauri-apps/api/mocks"
 *
 * afterEach(() => {
 *    clearMocks()
 * })
 *
 * test("mocked windows", () => {
 *    mockWindows("main", "second", "third");
 *
 *    expect(window.__TAURI_INTERNALS__).toHaveProperty("metadata")
 * })
 *
 * test("no mocked windows", () => {
 *    expect(window.__TAURI_INTERNALS__).not.toHaveProperty("metadata")
 * })
 * ```
 *
 * @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__.invoke
  // @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
  delete window.__TAURI_INTERNALS__.transformCallback
  // @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
  delete window.__TAURI_INTERNALS__.unregisterCallback
  // @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
  delete window.__TAURI_INTERNALS__.runCallback
  // @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
  delete window.__TAURI_INTERNALS__.callbacks
  // @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
  delete window.__TAURI_INTERNALS__.metadata
}


Review comment (bug):
Nitpick, but the double quote is closed incorrectly
```suggestion
  // @ts-expect-error "The operand of a 'delete' operator must be optional" does not matter in this case
```

Code after:
 * ```js
 * import { mockWindows, clearMocks } from "@tauri-apps/api/mocks"
 *
 * afterEach(() => {
 *    clearMocks()
 * })
 *
 * test("mocked windows", () => {
 *    mockWindows("main", "second", "third");
 *
 *    expect(window.__TAURI_INTERNALS__).toHaveProperty("metadata")
 * })
 *
 * test("no mocked windows", () => {
 *    expect(window.__TAURI_INTERNALS__).not.toHaveProperty("metadata")
 * })
 * ```
 *
 * @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__.invoke
  // @ts-expect-error "The operand of a 'delete' operator must be optional." does not matter in this case
  delete window.__TAURI_INTERNALS__.transformCallback
  // @ts-expect-error "The operand of a 'delete' operator must be optional." does not matter in this case
  delete window.__TAURI_INTERNALS__.unregisterCallback
  // @ts-expect-error "The operand of a 'delete' operator must be optional." does not matter in this case
  delete window.__TAURI_INTERNALS__.runCallback
  // @ts-expect-error "The operand of a 'delete' operator must be optional." does not matter in this case
  delete window.__TAURI_INTERNALS__.callbacks
  // @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
  delete window.__TAURI_INTERNALS__.metadata
}