validate.test.ts 1.0 KB

123456789101112131415161718192021222324252627
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { describe, expect, it } from 'vitest';
  6. import { hasError } from '../src/utils/validate';
  7. import { FeedbackLevel, FieldError } from '../src/types';
  8. describe('utils/validate', () => {
  9. describe('hasError', () => {
  10. it('should return false when errors is empty', () => {
  11. expect(hasError({ xxx: [] })).toBe(false);
  12. expect(hasError({ xxx: undefined })).toBe(false);
  13. expect(hasError({})).toBe(false);
  14. expect(hasError({ aaa: [], bbb: [] })).toBe(false);
  15. expect(hasError({ aaa: undefined, bbb: [] })).toBe(false);
  16. });
  17. it('should return true when errors is not empty', () => {
  18. const mockError: FieldError = { name: 'xxx', level: FeedbackLevel.Error, message: 'err' };
  19. expect(hasError({ xxx: [mockError] })).toBe(true);
  20. expect(hasError({ aaa: [mockError], bbb: [mockError] })).toBe(true);
  21. expect(hasError({ aaa: undefined, bbb: [mockError] })).toBe(true);
  22. });
  23. });
  24. });