Skip to content

Jest -u -t deletes all other snapshot files #8375

Closed
@GSynergy

Description

@GSynergy

🐛 Bug Report

Edit: Only happens when defining custom snapshot matchers such as toMatchTrimmedSnapshot from the docs.

As listed in documentation, I tried to use jest -u -t to only run and update the snapshot of a particular test. It did run and updated the snapshot for that test, however, all snapshot files for other (skipped) tests were deleted. Please see log below:

PASS tests/pattern.spec.js (7.224s)

Snapshot Summary
› 6 snapshot files removed from 6 test suites.

Test Suites: 10 skipped, 1 passed, 1 of 11 total
Tests: 72 skipped, 1 passed, 73 total
Snapshots: 6 files removed, 1 passed, 1 total
Time: 10.072s
Ran all test suites with tests matching "pattern.*".

To Reproduce

Steps to reproduce the behavior:

  1. Create two snapshot tests in two different spec files.
  2. Run all tests using jest. Check that the two tests have produced two different snapshot files
  3. Try updating the snapshot by using 'jest -u -t '
  4. Observe that the snapshots for other tests are deleted

Expected behavior

Snapshot of the test(s) matching the pattern should be updated. All other snapshots should remain intact

Link to repl or repo (highly encouraged)

https://github.com/GSynergy/Snapshot-Bug

Run npx envinfo --preset jest

Paste the results here:

npx: installed 1 in 2.324s

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i7-6567U CPU @ 3.30GHz
  Binaries:
    Node: 9.11.2 - ~/.nvm/versions/node/v9.11.2/bin/node
    Yarn: 1.12.3 - ~/.nvm/versions/node/v9.11.2/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v9.11.2/bin/npm
  npmPackages:
    jest: ^24.0.0 => 24.0.0 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions