Skip to content

Consider creating dedicated demo component for testing #941

@Rich-Harris

Description

@Rich-Harris

I just ran sv add vitest on an existing site and was slightly surprised to see it create src/routes/page.svelte.spec.ts. For one thing, the test it contained didn't pass, because it was making assumptions that might hold true for a freshly-baked app but won't necessarily hold true for existing apps.

But also: it feels weird to test components like +page.svelte. We don't know what props it might accept, or how it might interact with the layout, etc — if I want to test what happens when I visit / or any other route, that's really a job for an e2e test. I would typically expect a component test to belong to something in lib.

What if we created something like src/lib/Demo.svelte and src/lib/Demo.svelte.spec.ts instead? Maybe demo.spec.ts should go in lib too? (and also have a corresponding demo.ts module? It's slightly odd that the demo test isn't actually testing anything)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions