Skip to content

jest/no-large-snapshots doesn't work on external snap files #1353

@westthomas-dev

Description

@westthomas-dev

After configuring the jest/no-large snapshots rule, errors are only being raised for inline snapshots, not for external snapshot files.

Rule configuration:

"jest/no-large-snapshots": ["error", { "maxSize": 10, "inlineMaxSize": 10 }]

I have tried creating a new react app with typescript via CRA and configuring this rule in a clean application. It is detecting inline snapshot violations of the rule but no error is raised for separate .snap files.

I have followed the documentation adding the relevant plugins and set the ecmaVersion to latest.

The example uses the out of the box App.test.tsx / App.test.tsx.snap.

Snapshot test - App.test.tsx

test('matches snapshot', () => {
  const {container} = render(<App/>);
  expect(container).toMatchSnapshot();
})

Snapshot file contents - App.test.tsx.snap

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`matches snapshot 1`] = `
<div>
  <div
    class="App"
  >
    <header
      class="App-header"
    >
      <img
        alt="logo"
        class="App-logo"
        src="logo.svg"
      />
      <p>
        Edit 
        <code>
          src/App.tsx
        </code>
         and save to reload.
      </p>
      <a
        class="App-link"
        href="https://reactjs.org"
        rel="noopener noreferrer"
        target="_blank"
      >
        Learn React
      </a>
    </header>
  </div>
</div>
`;

Any advice or support would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions