Skip to content

[react-test-renderer] componentWillUnmount is not called for inner component instance #8459

@gre

Description

@gre

Do you want to request a feature or report a bug?

bug

What is the current behavior?

componentWillUnmount for inner instances is never called.

Here are 2 (jest) tests, the first works, not the second.

import React from "react";
import renderer from "react-test-renderer";

test("top level componentWillUnmount works", () => {
  let count = 0;
  class A extends React.Component {
    componentWillUnmount() {
      count ++;
    }
    render() {
      return <div />;
    }
  }
  const inst = renderer.create(<A />);
  inst.unmount();
  expect(count).toEqual(1);
});

test("inner componentWillUnmount works", () => {
  let count = 0;
  class A extends React.Component {
    componentWillUnmount() {
      count ++;
    }
    render() {
      return <div />;
    }
  }
  const inst = renderer.create(
    <div>
      <A />
    </div>
  );
  inst.unmount();
  expect(count).toEqual(1);
});

What is the expected behavior?

The two test above should pass. All component that are unmounted should have the proper lifecycle, whatever the nesting is.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

React 15.4.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions