Skip to content

Commit af3c909

Browse files
sebmarkbagegnoff
authored andcommitted
Update tests of the internal states
1 parent deb2aae commit af3c909

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

packages/react-dom/src/__tests__/ReactCompositeComponent-test.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,16 +537,24 @@ describe('ReactCompositeComponent', () => {
537537
});
538538

539539
it('should cleanup even if render() fatals', async () => {
540+
const dispatcherEnabled =
541+
__DEV__ ||
542+
!gate(flags => flags.disableStringRefs) ||
543+
gate(flags => flags.enableCache);
544+
const ownerEnabled = __DEV__ || !gate(flags => flags.disableStringRefs);
545+
546+
let stashedDispatcher;
540547
class BadComponent extends React.Component {
541548
render() {
549+
// Stash the dispatcher that was available in render so we can check
550+
// that its internals also reset.
551+
stashedDispatcher = ReactSharedInternals.A;
542552
throw new Error();
543553
}
544554
}
545555

546556
const instance = <BadComponent />;
547-
expect(ReactSharedInternals.owner).toBe(
548-
__DEV__ || !gate(flags => flags.disableStringRefs) ? null : undefined,
549-
);
557+
expect(ReactSharedInternals.A).toBe(dispatcherEnabled ? null : undefined);
550558

551559
const root = ReactDOMClient.createRoot(document.createElement('div'));
552560
await expect(async () => {
@@ -555,9 +563,16 @@ describe('ReactCompositeComponent', () => {
555563
});
556564
}).rejects.toThrow();
557565

558-
expect(ReactSharedInternals.owner).toBe(
559-
__DEV__ || !gate(flags => flags.disableStringRefs) ? null : undefined,
560-
);
566+
expect(ReactSharedInternals.A).toBe(dispatcherEnabled ? null : undefined);
567+
if (dispatcherEnabled) {
568+
if (ownerEnabled) {
569+
expect(stashedDispatcher.getOwner()).toBe(null);
570+
} else {
571+
expect(stashedDispatcher.getOwner).toBe(undefined);
572+
}
573+
} else {
574+
expect(stashedDispatcher).toBe(undefined);
575+
}
561576
});
562577

563578
it('should call componentWillUnmount before unmounting', async () => {

0 commit comments

Comments
 (0)