UNPKG

apphouse

Version:

Component library for React that uses observable state management and theme-able components.

44 lines (39 loc) 1.25 kB
import { validateField } from './validateField'; describe('validateField function', () => { it('should return true if the field is valid', () => { // Test case where the required field has a value and passes validation const result = validateField( 'example value', true, (value) => value === 'example value' ); expect(result).toBe(true); }); it('should return false if the field is required and has no value', () => { // Test case where the required field has no value const result = validateField( undefined, true, (value) => value === 'example value' ); expect(result).toBe(false); }); it('should return false if the field does not pass validation', () => { // Test case where the field does not pass validation const result = validateField( 'example value', true, (value) => value !== 'example value' ); expect(result).toBe(false); }); it('should return true if the field is not required', () => { // Test case where the field is not required (can have no value) const result = validateField( undefined, false, (value) => value !== 'example value' ); expect(result).toBe(true); }); });