Skip to content

[@angular/build:unit-test][vitest] Vitest snapshot testing #30439

Open
@timdeschryver

Description

@timdeschryver

Command

test

Description

Snapshot testing with Vitest is currently not supported.
The inline snapshots throw an error, and the file snapshots are stored in the dist folder which defeats the purpose of snapshot testing since these are not commited.

As an example see https://github.com/timdeschryver/VitestAngular/blob/main/src/app/app.spec.ts#L16.

Running the tests throws the following error:

TypeError: Cannot read properties of null (reading 'length')
 ❯ new MagicString ../../../node_modules/magic-string/src/MagicString.js:21:37
 ❯ ../../../node_modules/@vitest/snapshot/dist/index.js:1422:13
 ❯ saveInlineSnapshots ../../../node_modules/@vitest/snapshot/dist/index.js:1419:2
 ❯ SnapshotState.save ../../../node_modules/@vitest/snapshot/dist/index.js:1956:5
 ❯ SnapshotState.pack ../../../node_modules/@vitest/snapshot/dist/index.js:2107:18
 ❯ SnapshotClient.finish ../../../node_modules/@vitest/snapshot/dist/index.js:2149:18
 ❯ VitestTestRunner.onAfterRunSuite ../../../node_modules/vitest/dist/runners.js:162:19
 ❯ runSuite ../../../node_modules/@vitest/runner/dist/index.js:1537:3
 ❯ runFiles ../../../node_modules/@vitest/runner/dist/index.js:1561:3

Describe the solution you'd like

I'd like to be able to use Vitest's snapshot testing.

Describe alternatives you've considered

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions