Closed xmajzel closed 1 month ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hey, any updates on this? All needed to fix this is to remove double serialization in src/snapshot_file.ts as follows:
/**
* Returns the data needed for a future assertion
*/
getSnapshotTestData(test: Test, value: any) {
const snapshotName = this.getSnapshotName(test)
if (!this.#cachedContent) {
throw new Error(`Snapshot file ${this.#snapshotPath} not found`)
}
this.incrementTestCounter(test)
const expected = prepareExpected(this.#cachedContent[snapshotName])
const received = serializeSnapshotValue(value, this.#options.prettyFormatOptions)
return {
snapshotName,
- expected: prepareExpected(this.#cachedContent[snapshotName]),
+ expected,
- received: serializeSnapshotValue(received, this.#options.prettyFormatOptions),
+ received,
pass: expected === received,
}
}
Can provide PR if needed 😄
@Julien-R44
@thetutlage
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Sorry for the super late reply, especially as the fix was indeed super simple :/ New release is coming soon
Package version
2.0.5
Describe the bug
Bug description:
AssertionError.actual
compared toAssertionError.expected
differ, soAssertionError.actual
seems to print object on which have beenJSON.stringify()
called twice.Case 1 - file snapshot: Note - using Math.random() for book.rating, so it is always different, so the snapshot fails (after the first one is produced).
Produced output:
Case 2 - inline snapshot:
Produced output:
Expected behaviour:
For the Case 1, I would like, that it correctly show Number of changed lines as well as correct encoding (without double stringifying object - same for Case 2), e.g. how Jest does it (https://jestjs.io/docs/snapshot-testing#updating-snapshots):
Reproduction repo
No response