question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inline snapshots drift to the right

See original GitHub issue

💥 Regression Report

Inline snapshots are re-indented whenever another inline snapshot in the same file is saved/updated.

Last working version

Worked up to version: 24.5

Stopped working in version: 24.6

To Reproduce

Steps to reproduce the behavior:

Given this test file and we’re running in watch mode:

describe('broken', () => {
  test('1', () => {
    expect(11111).toMatchInlineSnapshot();
  });

  test('2', () => {
    expect([[1]]).toMatchInlineSnapshot();
  });
});

Upon save, both snapshots are written:

describe('broken', () => {
  test('1', () => {
    expect(11111).toMatchInlineSnapshot(`11111`);
  });

  test('2', () => {
    expect([[1]]).toMatchInlineSnapshot(`
      Array [
        Array [
          1,
        ],
      ]
    `);
  });
});

Now I update the first test (expect(10000).toMatchInlineSnapshot()) and save. The snapshots get rewritten:

describe('broken', () => {
  test('1', () => {
    expect(10000).toMatchInlineSnapshot(`10000`);
  });

  test('2', () => {
    expect([[1]]).toMatchInlineSnapshot(`
            Array [
              Array [
                1,
              ],
            ]
        `);
  });
});

Now I add another test (expect(3).toMatchInlineSnapshot()) and save:

describe('broken', () => {
  test('1', () => {
    expect(10000).toMatchInlineSnapshot(`10000`);
  });

  test('2', () => {
    expect([[1]]).toMatchInlineSnapshot(`
                  Array [
                    Array [
                      1,
                    ],
                  ]
            `);
  });

  test('3', () => {
    expect(3).toMatchInlineSnapshot(`3`);
  });
});

Notice how the snapshot for test 2 slowly drifts to the right. This can get super annoying after many test-update-save cycles.

Expected behavior

Inline snapshots should stay put.

Link to repl or repo (highly encouraged)

Repl.it only has Jest 22.1.2. I didn’t find a way to upgrade it.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS Mojave 10.14.4
    CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
  Binaries:
    Node: 10.15.0 - ~/.nvm/versions/node/v10.15.0/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v10.15.0/bin/npm
  npmPackages:
    jest: ^24.6.0 => 24.7.1 

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:21
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
SimenBcommented, Sep 4, 2019

24.9.0 has it 🙂

3reactions
jeysalcommented, May 18, 2019

Yeah definitely

Read more comments on GitHub >

github_iconTop Results From Across the Web

Snapshot Testing - Jest
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.
Read more >
Snapshot Testing - Jest - w3resource
Snapshot tests are a useful tool when you want to make sure your UI doesn't change unexpectedly. A typical snapshot test case for...
Read more >
Jest: How to Update Snapshot Tests - In Plain English
Snapshot tests are a great way to test UI without manually checking every element is visible, styled, and in the right place.
Read more >
Beau Mac Inline Slider Drift Float EVA - Cabela's
With its fluorescent top, this float is highly visible in low light; the fat cigar shape provides good stability and transfers the right...
Read more >
Drift Detection - Flyway - Product Documentation
Monitoring for Drift. Wouldn't it be nice to find out about drift in more real time instead of right before a deployment? Then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found