validate.test.ts 940 B

12345678910111213141516171819202122
  1. import { describe, expect, it } from 'vitest';
  2. import { hasError } from '../src/utils/validate';
  3. import { FeedbackLevel, FieldError } from '../src/types';
  4. describe('utils/validate', () => {
  5. describe('hasError', () => {
  6. it('should return false when errors is empty', () => {
  7. expect(hasError({ xxx: [] })).toBe(false);
  8. expect(hasError({ xxx: undefined })).toBe(false);
  9. expect(hasError({})).toBe(false);
  10. expect(hasError({ aaa: [], bbb: [] })).toBe(false);
  11. expect(hasError({ aaa: undefined, bbb: [] })).toBe(false);
  12. });
  13. it('should return true when errors is not empty', () => {
  14. const mockError: FieldError = { name: 'xxx', level: FeedbackLevel.Error, message: 'err' };
  15. expect(hasError({ xxx: [mockError] })).toBe(true);
  16. expect(hasError({ aaa: [mockError], bbb: [mockError] })).toBe(true);
  17. expect(hasError({ aaa: undefined, bbb: [mockError] })).toBe(true);
  18. });
  19. });
  20. });