fix bug in hasErrors with empty objects
Signed-off-by: Paul Cowan <paul.cowan@cutting.scot>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-react': patch
|
||||
---
|
||||
|
||||
fix bug with `hasErrors` returning false when dealing with empty objects
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,7 +35,9 @@ export function hasErrors(errors?: FormValidation): boolean {
|
||||
continue;
|
||||
}
|
||||
|
||||
return hasErrors(error);
|
||||
if (hasErrors(error)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user