Skip to content

(Windows) First test fails with "error: Failed to snapshot value" #10402

Answered by pragmatta
pragmatta asked this question in Q&A
Discussion options

You must be logged in to vote

Happened to figure this one out, the snapshotting can generate a snapshot file that it can't parse. While my tests where successful, it was actually failing read anything from the snapshot and basically treated the snapshot as empty and was writing the snapshots in the file over and over again.

What creates a corrupted snapshot is \x in data that gets treated as a hex escape sequence. For example this test (with valid CSV data)

test("dummy", () => {
        expect("\"x\\x\"").toMatchSnapshot()
})

generates snapshot

exports[`dummy 1`] = `""x\x""`;

Which is invalid Javascript (I assume the file gets evaluated).

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pragmatta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant