deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

[feature request] Add support for inline snapshots tests

Open niedzielski opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

Describe the solution you'd like

Jest inline shapshots are like file-based snapshots but much more casual. I love using them for small snapshots and I think they'd be a great improvement to Deno. From Jest's docs, they look like:

it('renders correctly', () => {
  const tree = renderer
    .create(<Link page="https://example.com">Example Site</Link>)
    .toJSON();
  expect(tree).toMatchInlineSnapshot(`
<a
  className="normal"
  href="https://example.com"
  onMouseEnter={[Function]}
  onMouseLeave={[Function]}
>
  Example Site
</a>
`);
});

The Deno version might look like:

Deno.test("renders correctly", async () => {
  const tree = renderer
    .create(<Link page="https://example.com">Example Site</Link>)
    .toJSON();
  await assertInlineSnapshot(`
<a
  className="normal"
  href="https://example.com"
  onMouseEnter={[Function]}
  onMouseLeave={[Function]}
>
  Example Site
</a>
`);
});

Describe alternatives you've considered

Right now, I just stick to the file-based snapshots which works fine but I find the locality of the inline snapshots much quicker to iterate on and they feel lightweight. I tend to avoid manual assertions more than a property or two as they're cumbersome to update.

niedzielski avatar Apr 02 '23 17:04 niedzielski

I too want this functionality. An additional benefit to inline snapshots is that read permissions only need to be granted along with write permissions when running --update, otherwise the expected value is inlined which means in CI/CD checks the read permission is not necessary unlike with external snapshots.

mfulton26 avatar Apr 28 '23 03:04 mfulton26