svelte-testing-library icon indicating copy to clipboard operation
svelte-testing-library copied to clipboard

Snapshot testing is breaking

Open allangrds opened this issue 3 years ago • 4 comments

Bug Report

Describe the bug

I get stuck when run a simple snapshot test with my component - it has not any prop.

Captura de Tela 2020-11-24 às 19 12 06

Expected behavior

Pass the test and generate a snapshot file.

Environment

Node: v12.18.2 OS: macOS Catalina 10.15.7

Additional context/Screenshots

My component Captura de Tela 2020-11-24 às 19 08 50

My test file Captura de Tela 2020-11-24 às 19 08 56

allangrds avatar Nov 24 '20 22:11 allangrds

This has to do with Svelte. A way around this would be to utilize a serializing function that converts DOM elements (and their children) into JSON in order to properly compare.

Edit: This is very specific to snapshot testing. The same is done for every other frontend library to my knowledge.

MirrorBytes avatar Dec 23 '20 16:12 MirrorBytes

Recommend looking at this for reference: https://gist.github.com/sstur/7379870

MirrorBytes avatar Dec 23 '20 16:12 MirrorBytes

@benmonro Want me to add a couple helper functions based on the above to aide in proper DOM snapshot testing?

MirrorBytes avatar Dec 26 '20 17:12 MirrorBytes

Sure

On Sat, Dec 26, 2020 at 9:37 AM Bob [email protected] wrote:

@benmonro https://github.com/benmonro Want me to add a couple helper functions based on the above to aide in proper DOM snapshot testing?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/testing-library/svelte-testing-library/issues/103#issuecomment-751378315, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADBPBHYZQSBN6ULQJ6RH5TSWYNOZANCNFSM4UBPCSBA .

-- Ben Monro Software Developer

benmonro avatar Dec 26 '20 18:12 benmonro

I'll go ahead and close this issue, as we have tests in the repo that use toMatchSnapshot() (https://github.com/testing-library/svelte-testing-library/blob/main/src/tests/render.test.js#L73)

yanick avatar Jan 23 '24 18:01 yanick