From 47a7be809343ae1ddce88055b56300b624df5ea0 Mon Sep 17 00:00:00 2001 From: Rob Madole Date: Wed, 22 May 2024 16:12:07 -0500 Subject: [PATCH] Handle undefined props like className (#564) --- .github/workflows/ci.yml | 14 ++------ src/components/FontAwesomeIcon.js | 2 +- .../__tests__/FontAwesomeIcon.test.js | 36 +++++++++++++++++++ 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60375bb6..c44c710a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,17 +10,9 @@ jobs: matrix: node: [14] react: [ - 16.3.x, - 16.4.x, - 16.5.x, - 16.6.x, - 16.7.x, - 16.8.x, - 16.9.x, - 16.10.x, - 16.11.x, - 16.12.x, - 17.0.x + 16.x, + 17.x, + 18.x ] fontawesome-svg-core: [ 1.2.x, diff --git a/src/components/FontAwesomeIcon.js b/src/components/FontAwesomeIcon.js index bd32a4af..915a09a8 100644 --- a/src/components/FontAwesomeIcon.js +++ b/src/components/FontAwesomeIcon.js @@ -53,7 +53,7 @@ const FontAwesomeIcon = React.forwardRef((props, ref) => { const classes = objectWithKey('classes', [ ...classList(allProps), - ...className.split(' ') + ...(className || '').split(' ') ]) const transform = objectWithKey( 'transform', diff --git a/src/components/__tests__/FontAwesomeIcon.test.js b/src/components/__tests__/FontAwesomeIcon.test.js index 13108c6f..1c77b8c5 100644 --- a/src/components/__tests__/FontAwesomeIcon.test.js +++ b/src/components/__tests__/FontAwesomeIcon.test.js @@ -73,6 +73,42 @@ if (coreHasFeature(REFERENCE_ICON_BY_STYLE)) { }) } +describe.only('using defaultProps', () => { + const UNDEFINED_DEFAULT_PROPS = { + border: undefined, + className: undefined, + mask: undefined, + maskId: undefined, + fixedWidth: undefined, + inverse: undefined, + flip: undefined, + listItem: undefined, + pull: undefined, + pulse: undefined, + rotation: undefined, + size: undefined, + spin: undefined, + spinPulse: undefined, + spinReverse: undefined, + beat: undefined, + fade: undefined, + beatFade: undefined, + bounce: undefined, + shake: undefined, + symbol: undefined, + title: undefined, + titleId: undefined, + transform: undefined, + swapOpacity: undefined + } + + test('undefined props passed', () => { + expect(() => + mount({ icon: faCoffee, ...UNDEFINED_DEFAULT_PROPS }) + ).not.toThrow(TypeError) + }) +}) + test('using imported object from svg icons package', () => { const vm = mount({ icon: faTimes