Skip to content

Commit

Permalink
Use gate pragma in ReacetOffscreenStrictMode test
Browse files Browse the repository at this point in the history
  • Loading branch information
sammy-SC committed Aug 12, 2022
1 parent bedfe3d commit b7856ae
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ describe('ReactOffscreenStrictMode', () => {
Offscreen = React.unstable_Offscreen;
ReactNoop = require('react-noop-renderer');
act = require('jest-react').act;

const ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableStrictEffects = __DEV__;
ReactFeatureFlags.createRootStrictEffectsByDefault = __DEV__;
});

function Component({label}) {
Expand All @@ -35,14 +31,15 @@ describe('ReactOffscreenStrictMode', () => {
return <span>label</span>;
}

// @gate enableOffscreen
// @gate __DEV__
// @gate __DEV__ && enableStrictEffects && enableOffscreen
it('should trigger strict effects when offscreen is visible', () => {
act(() => {
ReactNoop.render(
<Offscreen mode="visible">
<Component label="A" />
</Offscreen>,
<React.StrictMode>
<Offscreen mode="visible">
<Component label="A" />
</Offscreen>
</React.StrictMode>,
);
});

Expand All @@ -58,14 +55,15 @@ describe('ReactOffscreenStrictMode', () => {
]);
});

// @gate enableOffscreen
// @gate __DEV__
// @gate __DEV__ && enableStrictEffects && enableOffscreen
it('should not trigger strict effects when offscreen is hidden', () => {
act(() => {
ReactNoop.render(
<Offscreen mode="hidden">
<Component label="A" />
</Offscreen>,
<React.StrictMode>
<Offscreen mode="hidden">
<Component label="A" />
</Offscreen>
</React.StrictMode>,
);
});

Expand All @@ -75,9 +73,11 @@ describe('ReactOffscreenStrictMode', () => {

act(() => {
ReactNoop.render(
<Offscreen mode="visible">
<Component label="A" />
</Offscreen>,
<React.StrictMode>
<Offscreen mode="visible">
<Component label="A" />
</Offscreen>
</React.StrictMode>,
);
});

Expand Down
77 changes: 25 additions & 52 deletions packages/react/src/__tests__/ReactStrictMode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('ReactStrictMode', () => {
);
});

// @gate enableStrictEffects
// @gate __DEV__
it('should invoke precommit lifecycle methods twice', () => {
let log = [];
let shouldComponentUpdate = false;
Expand Down Expand Up @@ -108,26 +108,15 @@ describe('ReactStrictMode', () => {
container,
);

if (__DEV__) {
expect(log).toEqual([
'constructor',
'constructor',
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'render',
'render',
'componentDidMount',
'componentWillUnmount',
'componentDidMount',
]);
} else {
expect(log).toEqual([
'constructor',
'getDerivedStateFromProps',
'render',
'componentDidMount',
]);
}
expect(log).toEqual([
'constructor',
'constructor',
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'render',
'render',
'componentDidMount',
]);

log = [];
shouldComponentUpdate = true;
Expand All @@ -138,24 +127,15 @@ describe('ReactStrictMode', () => {
</React.StrictMode>,
container,
);
if (__DEV__) {
expect(log).toEqual([
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'shouldComponentUpdate',
'shouldComponentUpdate',
'render',
'render',
'componentDidUpdate',
]);
} else {
expect(log).toEqual([
'getDerivedStateFromProps',
'shouldComponentUpdate',
'render',
'componentDidUpdate',
]);
}
expect(log).toEqual([
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'shouldComponentUpdate',
'shouldComponentUpdate',
'render',
'render',
'componentDidUpdate',
]);

log = [];
shouldComponentUpdate = false;
Expand All @@ -167,19 +147,12 @@ describe('ReactStrictMode', () => {
container,
);

if (__DEV__) {
expect(log).toEqual([
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'shouldComponentUpdate',
'shouldComponentUpdate',
]);
} else {
expect(log).toEqual([
'getDerivedStateFromProps',
'shouldComponentUpdate',
]);
}
expect(log).toEqual([
'getDerivedStateFromProps',
'getDerivedStateFromProps',
'shouldComponentUpdate',
'shouldComponentUpdate',
]);
});

it('should invoke setState callbacks twice', () => {
Expand Down

0 comments on commit b7856ae

Please sign in to comment.