Skip to content

Inline snapshots are not written to js files containing JSX syntax when the file is located in a subfolder #11741

@JimMalmborg

Description

@JimMalmborg

💥 Regression Report

Inline snapshots are not written to JavaScript files containing JSX syntax when the file is located in a subfolder. It works fine if the file is at the root of the project. It also works fine for TypeScript files in both root and subfolders.

Last working version

Worked up to version: 26.6.3

Stopped working in version: 27.0.0

To Reproduce

Steps to reproduce the behavior:

  1. Create a React dev environment using the following packages or clone my repo.
"@babel/core": "^7.15.0",
"@babel/preset-env": "^7.15.0",
"@babel/preset-react": "^7.14.5",
"babel-jest": "^27.0.6",
"jest": "^27.0.6",
"prettier": "^2.3.2",
"react-test-renderer": "^17.0.2"
  1. Create a JavaScript test file in a subfolder e.g. ./src/inline-snapshot.spec.js
import React from 'react';
import TestRenderer from 'react-test-renderer';

it('should produce inline snapshot', () => {
  const result = TestRenderer.create(<span>test</span>).toJSON();
  expect(result).toMatchInlineSnapshot();
});

  1. Run the test using jest

Expected behavior

The inline snapshot should be written to the test file.

Link to repl or repo (highly encouraged)

https://replit.com/@JimMalmborg/inline-snapshot-regression?v=1

https://github.com/JimMalmborg/inline-snapshot.git
Run yarn and yarn test

Note! Manually clear any existing snapshots from the test files before running the tests.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Windows 10 10.0.19043
    CPU: (16) x64 Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz
  Binaries:
    Node: 15.4.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 7.0.15 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^27.0.6 => 27.0.6

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