diff --git a/js/src/helpers/isGutenbergAvailable.js b/js/src/helpers/isGutenbergAvailable.js index 32ec42df172..7a0379c7bd5 100644 --- a/js/src/helpers/isGutenbergAvailable.js +++ b/js/src/helpers/isGutenbergAvailable.js @@ -1,6 +1,6 @@ /* global wp */ -import isUndefined from "lodash/isUndefined"; +import isNil from "lodash/isNil"; import isFunction from "lodash/isFunction"; /** @@ -10,9 +10,9 @@ import isFunction from "lodash/isFunction"; */ export const isGutenbergDataAvailable = () => { return ( - ! isUndefined( window.wp ) && - ! isUndefined( wp.data ) && - ! isUndefined( wp.data.select( "core/editor" ) ) && + ! isNil( window.wp ) && + ! isNil( wp.data ) && + ! isNil( wp.data.select( "core/editor" ) ) && isFunction( wp.data.select( "core/editor" ).getEditedPostAttribute ) ); }; diff --git a/js/src/helpers/isGutenbergDataAvailable.js b/js/src/helpers/isGutenbergDataAvailable.js index 45ba21245a3..b1255182bfb 100644 --- a/js/src/helpers/isGutenbergDataAvailable.js +++ b/js/src/helpers/isGutenbergDataAvailable.js @@ -1,6 +1,6 @@ /* global wp */ -import isUndefined from "lodash/isUndefined"; +import isNil from "lodash/isNil"; import isFunction from "lodash/isFunction"; /** @@ -10,10 +10,10 @@ import isFunction from "lodash/isFunction"; */ const isGutenbergDataAvailable = () => { return ( - ! isUndefined( window.wp ) && - ! isUndefined( wp.data ) && - ! isUndefined( wp.data.select( "core/edit-post" ) ) && - ! isUndefined( wp.data.select( "core/editor" ) ) && + ! isNil( window.wp ) && + ! isNil( wp.data ) && + ! isNil( wp.data.select( "core/edit-post" ) ) && + ! isNil( wp.data.select( "core/editor" ) ) && isFunction( wp.data.select( "core/editor" ).getEditedPostAttribute ) ); }; diff --git a/js/tests/isGutenbergAvailable.test.js b/js/tests/isGutenbergAvailable.test.js index d998747ea61..0490079e3e7 100644 --- a/js/tests/isGutenbergAvailable.test.js +++ b/js/tests/isGutenbergAvailable.test.js @@ -26,4 +26,10 @@ describe( "isGutenbergDataAvailable", () => { const actual = isGutenbergDataAvailable(); expect( actual ).toBe( false ); } ); + + it( "returns false if wp.data is available but the required selectors not registered", () => { + window.wp = { data: { select: () => null } }; + const actual = isGutenbergDataAvailable(); + expect( actual ).toBe( false ); + } ); } );