Form
Learn about form in fp-ts validation
Code Editor
04-form.exercise.ts
💻
Loading editor...
Preparing Monaco Editor with TypeScript support
Test Results
Requirements
describe('Form validation', () => {
it('validates correct form', () => {
const form = {
username: 'alice123',
email: 'alice@example.com',
password: 'SecurePass123',
confirmPassword: 'SecurePass123',
}
const result = validateForm(form)
expect(result._tag).toBe('Right')
})
it('accumulates all form errors', () => {
const form = {
username: 'a!',
email: 'invalid',
password: 'weak',
confirmPassword: 'different',
}
const result = validateForm(form)
expect(result._tag).toBe('Left')
if (result._tag === 'Left') {
expect(result.left.length).toBeGreaterThan(3)
}
})
it('detects password mismatch', () => {
const form = {
username: 'alice',
email: 'alice@example.com',
password: 'SecurePass123',
confirmPassword: 'DifferentPass123',
}
const result = validateForm(form)
expect(result._tag).toBe('Left')
if (result._tag === 'Left') {
expect(result.left).toContain('Passwords do not match')
}
})
})🧪
Ready to Test?
Click "Run Tests" to see how your code performs
Quick Tips
•Read the TODO comments in the code
•Use Reset to restore original code
•Check Solution if stuck
Pro Tips
💡 Stuck? Here's what to try:
- • Read the comments in the code carefully
- • Run tests frequently to get feedback
- • Check the fp-ts documentation
- • Use the solution if you need help
🚀 Learning Approach:
- • Focus on understanding, not just solving
- • Experiment with different approaches
- • Think about real-world applications
- • Build on previous exercises