Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Add support for inline snapshots tests #3301

Open
niedzielski opened this issue Apr 2, 2023 · 4 comments
Open

[feature request] Add support for inline snapshots tests #3301

niedzielski opened this issue Apr 2, 2023 · 4 comments

Comments

@niedzielski
Copy link

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.

@mfulton26
Copy link
Contributor

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.

@douglasduteil
Copy link
Contributor

Linked to #3964

@kt3k
Copy link
Member

kt3k commented Nov 26, 2024

What does jest use for modifying the source code?

@nicolo-ribaudo
Copy link

Babel, and then reformats the code with prettier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants