Skip to content

Unify the provider-guard "throws outside its provider" test pattern #271

Description

@Zaldaryon

Two renderer tests assert that a context hook throws when used outside its provider, and they do it two different ways:

  • tests/renderer-dom/configContextSlices.test.tsx:167 lets the render throw escape and silences the fallout: vi.spyOn(console, "error").mockImplementation(() => {}) plus a window error listener that calls preventDefault().
  • tests/renderer-dom/taskManagerFlows.test.tsx (after test(renderer): keep the TaskProvider guard throw inside the component #264) catches the throw inside the render callback so React never runs its guarded replay, then asserts console.error was not called as a regression pin.

The catch-inside approach from #264 is the better one. It does not depend on jsdom's window error machinery or on Vitest's global error-listener bookkeeping, and it fails loudly if a future edit lets the throw escape again. #264 explains why the escaping form is a run-level flake risk.

Proposed, test-only, no production change:

  1. Move configContextSlices.test.tsx:167 to the same catch-inside pattern.
  2. useNotificationsContext (src/renderer/src/contexts/NotificationsContext.tsx:145) has no outside-provider test at all. Add one in the same style so that guard branch is covered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerstech debtInherited debt, tracked to be paid down

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions