Skip to content

test(styled-tools): add unit tests - #296

Merged
Komoszek merged 2 commits into
mainfrom
test/styled-tools
Jun 25, 2026
Merged

Komoszek merged 2 commits into
mainfrom
test/styled-tools

Conversation

@claude

@claude claude Bot commented Jun 25, 2026

Copy link
Copy Markdown

Requested by Sebastian Konowrocki · Slack thread

Before / After

@leancodepl/styled-tools previously had no tests. This PR adds 19 unit tests covering the package's entire public surface:

  • mkProxy (13 tests): direct accessor invocation, lazy nested property traversal, deep multi-level resolution, the prototype special case (returns Function.prototype), proxy caching (same reference for repeated access, distinct proxies per key), per-invocation re-evaluation against the execution context, symbol-keyed access, and the guard edge cases (property access on string/number/null/missing/undefined values all resolve to undefined).
  • mkTheme (6 tests): the returned { theme, useTheme } shape, the theme proxy reading nested values out of the styled-components ExecutionContext (including theme switching and non-existent paths), and the useTheme hook resolving the active ThemeProvider theme via @testing-library/react's renderHook.

How

Mirrored the vitest conventions of sibling packages (jsdom env, renderHook + ThemeProvider for the hook). Added @testing-library/react, react, and vitest to devDependencies to satisfy the workspace lint rules, matching how other tested packages declare them. All of :test, :typecheck, :lint, and :build pass locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DXXPnGepYUGie3we1X9PTR


Generated by Claude Code

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXXPnGepYUGie3we1X9PTR
@claude
claude Bot marked this pull request as ready for review June 25, 2026 09:35
it("returns undefined for a path that does not exist on the theme", () => {
const { theme } = mkTheme<AppTheme>()

const missing = (theme.colors as any).tertiary as (c: ExecutionContext) => unknown

@Komoszek Komoszek Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it implies bypassing typesafety of the theme. Does this test make sense?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Masz rację — ten test obchodził typesafety: sięgał po theme.colors.tertiary przez as any, czyli po klucz, którego AppTheme (i typ TransformDeep<TTheme>, którego cały sens to typowanie ścieżek) i tak nie dopuści w czasie kompilacji. Samo runtime'owe zachowanie "brakująca ścieżka → undefined" należy do mkProxy i jest już bezpośrednio pokryte w mkProxy.spec.ts ("returns undefined for a missing property on an object value"), na poprawnie typowanym Value. Test nie wnosił więc realnego pokrycia — usunąłem go.

… safety

The removed test reached a key absent from AppTheme via an `as any`
cast, exercising a path mkTheme's TransformDeep type forbids at compile
time. The underlying missing-property runtime behavior is owned by
mkProxy and already covered directly in mkProxy.spec.ts, so the test
added no meaningful coverage.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXXPnGepYUGie3we1X9PTR
@Komoszek
Komoszek merged commit 1197ef5 into main Jun 25, 2026
1 check passed
@Komoszek
Komoszek deleted the test/styled-tools branch June 25, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants