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

Inline snapshots indented at col 0 when existing inline snapshots in file #9477

Closed
jedrichards opened this issue Jan 28, 2020 · 4 comments · Fixed by #9523
Closed

Inline snapshots indented at col 0 when existing inline snapshots in file #9477

jedrichards opened this issue Jan 28, 2020 · 4 comments · Fixed by #9523

Comments

@jedrichards
Copy link

jedrichards commented Jan 28, 2020

🐛 Bug Report

When a new inline snapshot is generated in a file that already contains inline snapshots, the new snapshot content is incorrectly indented far left, at column 0.

To Reproduce

The following code upon file save produces a correctly indented snapshot:

test('test', () => {
  expect(['Hello world']).toMatchInlineSnapshot()
})

Becomes -

test('test', () => {
  expect(['Hello world']).toMatchInlineSnapshot(`
    Array [
      "Hello world",
    ]
  `)
})

However, with two test blocks present, the first already containing an inline snapshot -

test('test', () => {
  expect(['Hello world']).toMatchInlineSnapshot(`
    Array [
      "Hello world",
    ]
  `)
})

test('test', () => {
  expect(['Hello world']).toMatchInlineSnapshot()
})

On save, becomes -

test('test', () => {
  expect(['Hello world']).toMatchInlineSnapshot(`
    Array [
      "Hello world",
    ]
  `)
})

test('test', () => {
  expect(['Hello world']).toMatchInlineSnapshot(`
Array [
  "Hello world",
]
`)
})

Expected behavior

In the second example above, I would expect the snapshot in the second test block to be indented the same as the first, not hard left.

envinfo

System:
    OS: macOS 10.15.2
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
  Binaries:
    Node: 12.6.0 - ~/.nvm/versions/node/v12.6.0/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v12.6.0/bin/npm
  npmPackages:
    jest: 25.1.0 => 25.1.0 
@G-Rath
Copy link
Contributor

G-Rath commented Feb 2, 2020

I've got this as well - I'd think it's b/c of #9203, but I've attempted a revert to no effect.

I'll have a poke around to see if I can find what has caused this to regress from 24.9 - will also need to find a way to make a test; jest might already have some "run twice" tests, but not hopefully something can be hacked together.

@SimenB
Copy link
Member

SimenB commented Feb 3, 2020

I've bisected this, it regressed in #9278.

@G-Rath thanks for looking into it! For a test, there's no need to run twice, just have the middle example from the OP and run that

@G-Rath
Copy link
Contributor

G-Rath commented Feb 5, 2020

@SimenB can you assign this to me? I've got a fix incoming.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants