syrupy icon indicating copy to clipboard operation
syrupy copied to clipboard

Inline snapshot testing

Open msrose opened this issue 5 years ago • 2 comments

Opening an issue for discussion purposes, no defined requirements or suggestions for how (or whether) this should be implemented):

See https://jestjs.io/docs/en/snapshot-testing#inline-snapshots for how jest handles inline snapshots.

It would be cool if syrupy could support something this since it's really nice for certain cases.

msrose avatar Jan 31 '20 20:01 msrose

Ignoring the complications of modifying the source code for automatic snapshot insertion, what would the syntax look like?

assert actual_data == snapshot(inline="")

Where the presence of the inline key prevents the snapshot from being written to file and the failure diff shows what needs to be copied into the inline string.

assert actual_data == snapshot(inline="""
  dict({
    'list': list([
      2,
    ]),
    'nested': dict({
      'other': 'value',
    }),
  })
""")

Or maybe it can a snapshot extension instead?

iamogbz avatar Jul 20 '23 20:07 iamogbz

hi, I'm the author of inline-snapshot and I found this issue while I was reading through your issues to find inspiration for my own library.

Maybe inline-snapshot provides some inspiration for you, because putting the values into the source code is its the main function.

sneak peek:

from inline_snapshot import snapshot

data = dict(
    {
        "list": list([2]),
        "nested": dict({"other": "value"}),
    }
)


def test_data():
    assert data == snapshot({"list": [2], "nested": {"other": "value"}})

15r10nk avatar Oct 23 '23 17:10 15r10nk