diff --git a/.changeset/happy-boxes-arrive.md b/.changeset/happy-boxes-arrive.md new file mode 100644 index 0000000000..85998c1bdd --- /dev/null +++ b/.changeset/happy-boxes-arrive.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-react': patch +--- + +fix bug with `hasErrors` returning false when dealing with empty objects diff --git a/plugins/scaffolder-react/src/next/components/Stepper/utils.test.ts b/plugins/scaffolder-react/src/next/components/Stepper/utils.test.ts index f6a1b012ac..e07c4e5508 100644 --- a/plugins/scaffolder-react/src/next/components/Stepper/utils.test.ts +++ b/plugins/scaffolder-react/src/next/components/Stepper/utils.test.ts @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { type FormValidation } from './createAsyncValidators'; import { hasErrors } from './utils'; describe('hasErrors', () => { @@ -58,4 +59,35 @@ describe('hasErrors', () => { }), ).toBe(true); }); + + it('should not return false when the error is an empty object', () => { + const errors = { + something: {}, + otherThing: {}, + someName: { + __errors: [ + 'Accepts alphanumeric values along with _(underscore) and -(hypen) as special characters', + ], + addError: jest.fn(), + }, + someOtherName: { + __errors: ['Must start with an alphabet & not contain .(period)'], + addError: jest.fn(), + }, + aName: { + __errors: [], + addError: jest.fn(), + }, + bName: { + __errors: [], + addError: jest.fn(), + }, + cName: { + __errors: [], + addError: jest.fn(), + }, + }; + + expect(hasErrors(errors)).toBe(true); + }); }); diff --git a/plugins/scaffolder-react/src/next/components/Stepper/utils.ts b/plugins/scaffolder-react/src/next/components/Stepper/utils.ts index 7d3efa9d94..0b70f57813 100644 --- a/plugins/scaffolder-react/src/next/components/Stepper/utils.ts +++ b/plugins/scaffolder-react/src/next/components/Stepper/utils.ts @@ -35,7 +35,9 @@ export function hasErrors(errors?: FormValidation): boolean { continue; } - return hasErrors(error); + if (hasErrors(error)) { + return true; + } } return false;