Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Failing test for false positive warning
  • Loading branch information
gaearon authored and acdlite committed May 14, 2019
commit ead0ccc8db0ff0450260307a028b685bbe88e133
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,57 @@ describe('ReactHooks', () => {
).toThrow('Hello');
});

it('does not fire a false positive warning when previous effect unmounts the component', () => {
let {useState, useEffect} = React;
let globalListener;

function A() {
const [show, setShow] = useState(true);
function hideMe() {
setShow(false);
}
return show ? <B hideMe={hideMe} /> : null;
}

function B(props) {
return <C {...props} />;
}

function C({hideMe}) {
const [, setState] = useState();

useEffect(() => {
let isStale = false;

globalListener = () => {
if (!isStale) {
setState('hello');
}
};

return () => {
isStale = true;
hideMe();
};
});
return null;
}

ReactTestRenderer.act(() => {
ReactTestRenderer.create(<A />);
});

expect(() => {
globalListener();
globalListener();
}).toWarnDev([
'An update to C inside a test was not wrapped in act',
'An update to C inside a test was not wrapped in act',
// Note: should *not* warn about updates on unmounted component.
// Because there's no way for component to know it got unmounted.
]);
});

// Regression test for https://github.com/facebook/react/issues/14790
it('does not fire a false positive warning when suspending memo', async () => {
const {Suspense, useState} = React;
Expand Down