Api

advanced9 of 10

Learn about api in fp-ts taskeither

Code Editor

09-api.exercise.ts

💻
Loading editor...
Preparing Monaco Editor with TypeScript support

Test Results

Requirements

describe('TaskEither API operations', () => {
  it('fetches user successfully', async () => {
    const result = await fetchUser(1)()
    expect(result._tag).toBe('Right')
    if (result._tag === 'Right') {
      expect(result.right.id).toBe(1)
      expect(result.right.name).toBe('User 1')
    }
  })

  it('handles API error', async () => {
    const result = await fetchUser(0)()
    expect(result._tag).toBe('Left')
    if (result._tag === 'Left') {
      expect(result.left.status).toBe(404)
    }
  })

  it('updates user email', async () => {
    const result = await updateUserEmail(1, 'newemail@example.com')()
    expect(result._tag).toBe('Right')
    if (result._tag === 'Right') {
      expect(result.right.email).toBe('newemail@example.com')
    }
  })
})
🧪

Ready to Test?

Click "Run Tests" to see how your code performs

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