diff --git a/assets/src/block-editor/helpers/index.js b/assets/src/block-editor/helpers/index.js index a673ae706cc..a737d53890f 100644 --- a/assets/src/block-editor/helpers/index.js +++ b/assets/src/block-editor/helpers/index.js @@ -417,10 +417,10 @@ AmpLayoutControl.propTypes = { * * @return {ReactElement} Element. */ -const AmpNoloadingToggle = ( props ) => { +export const AmpNoloadingToggle = ( props ) => { const { attributes: { ampNoLoading }, setAttributes } = props; - if ( ! ampNoLoading ) { + if ( undefined === ampNoLoading ) { return null; } diff --git a/assets/src/block-editor/helpers/test/AmpNoloadingToggle.js b/assets/src/block-editor/helpers/test/AmpNoloadingToggle.js new file mode 100644 index 00000000000..b159717ed2a --- /dev/null +++ b/assets/src/block-editor/helpers/test/AmpNoloadingToggle.js @@ -0,0 +1,46 @@ +/** + * External dependencies + */ +import { act } from 'react-dom/test-utils'; + +/** + * WordPress dependencies + */ +import { render } from '@wordpress/element'; + +/** + * Internal dependencies + */ +import { AmpNoloadingToggle } from '../'; + +let container; + +describe( 'AmpNoloadingToggle', () => { + beforeEach( () => { + container = document.createElement( 'div' ); + document.body.appendChild( container ); + } ); + + afterEach( () => { + document.body.removeChild( container ); + container = null; + } ); + + it( 'should not render if ampNoLoading is undefined', function() { + act( () => { + render( {} } attributes={ {} } />, container ); + } ); + + const selectControl = container.querySelector( 'input' ); + expect( selectControl ).toBeNull(); + } ); + + it( 'should render if ampNoLoading is defined', function() { + act( () => { + render( {} } attributes={ { ampNoLoading: true } } />, container ); + } ); + + const selectControl = container.querySelector( 'input' ); + expect( selectControl ).not.toBeNull(); + } ); +} );