Skip to content

Commit

Permalink
fix: add Profiler support for adapter-react-16
Browse files Browse the repository at this point in the history
  • Loading branch information
holsted committed Sep 7, 2019
1 parent d26ccd4 commit 49fccc8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/enzyme-adapter-react-16/src/detectFiberTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = function detectFiberTags() {
const supportsContext = typeof React.createContext !== 'undefined';
const supportsForwardRef = typeof React.forwardRef !== 'undefined';
const supportsMemo = typeof React.memo !== 'undefined';
const supportsProfiler = typeof React.unstable_Profiler !== 'undefined';
const supportsProfiler = typeof React.unstable_Profiler !== 'undefined' || typeof React.Profiler !== 'undefined';
const supportsSuspense = typeof React.Suspense !== 'undefined';
const supportsLazy = typeof React.lazy !== 'undefined';

Expand Down Expand Up @@ -99,7 +99,7 @@ module.exports = function detectFiberTags() {
? getFiber(React.createElement(FwdRef)).tag
: -1,
Profiler: supportsProfiler
? getFiber(React.createElement(React.unstable_Profiler, { id: 'mock', onRender() {} })).tag
? getFiber(React.createElement((React.Profiler || React.unstable_Profiler), { id: 'mock', onRender() {} })).tag
: -1,
Suspense: supportsSuspense
? getFiber(React.createElement(React.Suspense, { fallback: false })).tag
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-test-suite/test/Adapter-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ describe('Adapter', () => {
expect(getDisplayName(<Profiler />)).to.equal('Profiler');
});

itIf(is('>= 16.6'), 'supports ConcurrentMode', () => {
itIf((is('>= 16.6') && is('<16.9')), 'supports ConcurrentMode', () => {
expect(getDisplayName(<ConcurrentMode />)).to.equal('ConcurrentMode');
});

Expand Down
12 changes: 10 additions & 2 deletions packages/enzyme-test-suite/test/_helpers/react-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,23 @@ if (is('^16.3.0-0')) {
AsyncMode = null;
}

if (is('^16.4.0-0')) {
if (is('^16.9.0-0')) {
({ Profiler } = require('react'));
} else if (is('^16.4.0-0')) {
({
unstable_Profiler: Profiler,
} = require('react'));
} else {
Profiler = null;
}

if (is('^16.6.0-0')) {
if (is('^16.9.0-0')) {
({
Suspense,
lazy,
memo,
} = require('react'));
} else if (is('^16.6.0-0')) {
({
unstable_ConcurrentMode: ConcurrentMode,
Suspense,
Expand Down

0 comments on commit 49fccc8

Please sign in to comment.