Skip to content

Assignments from Viktoria Valova#9

Open
valovaViktoria wants to merge 20 commits intoanko-code-academy:mainfrom
valovaViktoria:assignments
Open

Assignments from Viktoria Valova#9
valovaViktoria wants to merge 20 commits intoanko-code-academy:mainfrom
valovaViktoria:assignments

Conversation

@valovaViktoria
Copy link
Copy Markdown

@valovaViktoria valovaViktoria commented Dec 14, 2025

Assignment: 01 - Deep Clone

Checklist

  • All tests pass (npm run test:01)
  • Code follows the existing style
  • No modifications to test files

Assignment: 02 - Debounce & Throttle

Checklist

  • All tests pass (npm run test:02)
  • Code follows the existing style
  • No modifications to test files

Assignment: 03 - Custom Bind

Checklist

  • All tests pass (npm run test:03)
  • Code follows the existing style
  • No modifications to test files

Assignment: 04 - Memoization

Checklist

  • All tests pass (npm run test:04)
  • Code follows the existing style
  • No modifications to test files

Assignment: 05 - Custom Bind

Checklist

  • All tests pass (npm run test:05)
  • Code follows the existing style
  • No modifications to test files

Assignment: 06 -Async Queue

Checklist

  • All tests pass (npm run test:06)
  • Code follows the existing style
  • No modifications to test files

Test Timing Fix
Problem: Jest fake timers created race conditions with onEmpty callbacks
Solution: Added delay(10) calls to ensure proper timing synchronization
Impact: Tests now reliably trigger callbacks when queue becomes empty

Assignment: 07 - Retry With Backoff

Checklist

  • All tests pass (npm run test:07)
  • Code follows the existing style
  • No modifications to test files

Jest Timing & Rejection Handling
Initial Approach: Implemented runner = (async() => {})() IIFE pattern as demonstrated in class

Encountered Issue:
Tests failed with unhandled promise rejection errors
Jest's advanceTimersByTimeAsync() advances timers, but promise rejections happen immediately
This created race conditions: rejections occurred before expect().rejects.toThrow() could handle them

Solution:
Removed IIFE wrapper pattern, made retry function directly async (simplified implementation)
Created preventUnhandledRejection wrapper in tests to handle rejection timing with Jest fake timers
Applied wrapper to all test cases expecting promise rejections

Impact: Tests now reliably handle promise rejections without timing conflicts

Assignment: 08 - Event Emitter

Checklist

  • All tests pass (npm run test:08)
  • Code follows the existing style
  • No modifications to test files

Assignment: 09 - Observable

Checklist

  • All tests pass (npm run test:09)
  • Code follows the existing style
  • No modifications to test files

Assignment: 10 - LRU Cache

Checklist

  • All tests pass (npm run test:10)
  • Code follows the existing style
  • No modifications to test files

Assignment: 11 -Singleton

Checklist

  • All tests pass (npm run test:11)
  • Code follows the existing style
  • No modifications to test files

Assignment: 12 -Factory Pattern

Checklist

  • All tests pass (npm run test:12)
  • Code follows the existing style
  • No modifications to test files

Assignment: 13 - Decorator Pattern

Checklist

  • All tests pass (npm run test:13)
  • Code follows the existing style
  • No modifications to test files

Assignment: 14 - Middleware Pipeline

Checklist

  • All tests pass (npm run test:14)
  • Code follows the existing style
  • No modifications to test files

Assignment: 15 - Dependency Injection

Checklist

  • All tests pass (npm run test:15)
  • Code follows the existing style
  • No modifications to test files

Assignment: 16 - State Machine

Checklist

  • All tests pass (npm run test:16)
  • Code follows the existing style
  • No modifications to test files

Assignment: 17 - Command Pattern

Checklist

  • All tests pass (npm run test:17)
  • Code follows the existing style
  • No modifications to test files

Assignment: 18 - Strategy Pattern

Checklist

  • All tests pass (npm run test:18)
  • Code follows the existing style
  • No modifications to test files

Assignment: 19 - Proxy Pattern

Checklist

  • All tests pass (npm run test:19)
  • Code follows the existing style
  • No modifications to test files

Assignment: 20 - Builder Pattern

Checklist

  • All tests pass (npm run test:20)
  • Code follows the existing style
  • No modifications to test files

Testing:

All tests pass locally

Resolve timing issues in onEmpty tests:
- added delay(10) to "should call callback when queue becomes empty"
- added delay(10) to "should support multiple onEmpty callbacks"
Prevented unhandled promise rejections with preventUnhandledRejection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant