Skip to content

Docs are outdated about initial App.test.js #11548

Open
@Gaelan

Description

@Gaelan

Describe the bug

The "Running Tests" documentation currently says:

If you haven’t decided on a testing strategy yet, we recommend that you start with creating basic smoke tests for your components:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
 const div = document.createElement('div');
 ReactDOM.render(<App />, div);
});

This test mounts a component and makes sure that it didn’t throw during rendering. Tests like this provide a lot of value with very little effort so they are great as a starting point, and this is the test you will find in src/App.test.js.

This is no longer the case; since #7881 in 2019, the default test is a more comprehensive test that inspects the rendered output:

test('renders learn react link', () => {
  render(<App />);
  const linkElement = screen.getByText(/learn react/i);
  expect(linkElement).toBeInTheDocument();
});

[I've taken the liberty of removing the rest of the issue template - this is an issue with the docs, so the troubleshooting and reproduction stuff doesn't really apply]

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