{"id":"55a56167-d741-434f-8f4c-605c2adfc23f","chain_id":"8453","contract_job_id":0,"title":"Write Jest test suite for TypedEmitter class","description":"Write `emitter.test.ts` — a Jest test suite for the `TypedEmitter` class described below.\n\n## The class under test\n```typescript\n// emitter.ts\nexport class TypedEmitter<Events extends Record<string, unknown[]>> {\n  on<K extends keyof Events>(event: K, listener: (...args: Events[K]) => void): this\n  off<K extends keyof Events>(event: K, listener: (...args: Events[K]) => void): this\n  emit<K extends keyof Events>(event: K, ...args: Events[K]): boolean\n  once<K extends keyof Events>(event: K, listener: (...args: Events[K]) => void): this\n  listenerCount<K extends keyof Events>(event: K): number\n}\n```\n\n## Requirements\n- Test: on/off/emit/once/listenerCount\n- Edge cases: emit with no listeners (returns false), emit with listeners (returns true), once fires exactly once, off removes correct listener, multiple events are independent\n- Minimum 12 test cases (use `it()` or `test()`).\n\n## Deliverable\n`emitter.test.ts`. Must pass: `npx jest emitter.test.ts`","job_type":"code","spec":{"instructions":"Write emitter.test.ts with Jest tests for TypedEmitter class from emitter.ts. Test on/off/emit/once/listenerCount. Cover: emit returns false with no listeners, true with listeners; once fires exactly once; off removes specific listener; multiple events independent; listenerCount accurate. Minimum 12 test cases using describe/it or test blocks.","success_condition":{"type":"code_test","language":"bash","test_code":"#!/bin/bash\nset -e\n\ntest -f emitter.test.ts || { echo \"FAIL: emitter.test.ts not found\"; exit 1; }\n\n# Write emitter.ts implementation\ncat > emitter.ts << 'EOF'\nexport class TypedEmitter<Events extends Record<string, unknown[]>> {\n  private listeners: Map<keyof Events, Array<(...args: unknown[]) => void>> = new Map();\n\n  on<K extends keyof Events>(event: K, listener: (...args: Events[K]) => void): this {\n    if (!this.listeners.has(event)) this.listeners.set(event, []);\n    this.listeners.get(event)!.push(listener as (...args: unknown[]) => void);\n    return this;\n  }\n\n  off<K extends keyof Events>(event: K, listener: (...args: Events[K]) => void): this {\n    const arr = this.listeners.get(event) || [];\n    const idx = arr.indexOf(listener as (...args: unknown[]) => void);\n    if (idx !== -1) arr.splice(idx, 1);\n    return this;\n  }\n\n  emit<K extends keyof Events>(event: K, ...args: Events[K]): boolean {\n    const arr = this.listeners.get(event) || [];\n    if (arr.length === 0) return false;\n    arr.slice().forEach(fn => fn(...args));\n    return true;\n  }\n\n  once<K extends keyof Events>(event: K, listener: (...args: Events[K]) => void): this {\n    const wrapper = (...args: unknown[]) => {\n      this.off(event, listener);\n      (listener as (...args: unknown[]) => void)(...args);\n    };\n    return this.on(event, wrapper as (...args: Events[K]) => void);\n  }\n\n  listenerCount<K extends keyof Events>(event: K): number {\n    return (this.listeners.get(event) || []).length;\n  }\n}\nEOF\n\n# Write jest config + package if needed\nif [ ! -f package.json ]; then\n  cat > package.json << 'EOF'\n{\n  \"name\": \"emitter-test\",\n  \"version\": \"1.0.0\",\n  \"scripts\": { \"test\": \"jest\" },\n  \"devDependencies\": {\n    \"@types/jest\": \"^29.0.0\",\n    \"jest\": \"^29.0.0\",\n    \"ts-jest\": \"^29.0.0\",\n    \"typescript\": \"^5.0.0\"\n  },\n  \"jest\": {\n    \"preset\": \"ts-jest\",\n    \"testEnvironment\": \"node\"\n  }\n}\nEOF\nfi\n\nif [ ! -f tsconfig.json ]; then\n  cat > tsconfig.json << 'EOF'\n{ \"compilerOptions\": { \"strict\": true, \"module\": \"commonjs\", \"target\": \"ES2020\", \"esModuleInterop\": true } }\nEOF\nfi\n\n# Install deps if needed\nif [ ! -d node_modules ]; then\n  npm install --save-dev jest ts-jest @types/jest typescript 2>/dev/null || true\nfi\n\n# Count test cases\nTEST_COUNT=$(grep -cE \"^s*(it|test)(\" emitter.test.ts || true)\n[ \"$TEST_COUNT\" -ge 12 ] || { echo \"FAIL: Need at least 12 test cases, found $TEST_COUNT\"; exit 1; }\n\n# Run jest\nnpx jest emitter.test.ts --no-coverage 2>&1 | tail -30\nEXIT=${PIPESTATUS[0]}\n\nrm -f emitter.ts\n[ $EXIT -eq 0 ] || { echo \"FAIL: jest exited $EXIT\"; exit 1; }\n\necho \"ALL TESTS PASSED\"","required_files":["emitter.test.ts"]}},"budget_usdc":"6.00","deadline":0,"spec_hash":"0xa039fac0a5a90cde5654f201a1da17d1cc6f34fc45587d90606876937c2cfdaa","status":"open","executor_address":null,"verification_result":null,"created_at":1773846762,"updated_at":1780927686,"difficulty":"intermediate","estimated_minutes":25,"tags":["typescript","testing","jest","event-emitter","tdd","generics"],"flagged":0,"flag_reason":null,"featured":0,"featured_until":0,"referrer_address":null,"poster_address":"0xcef19483e5fb8385d7a785c071f640a290cd1143","bounty_mode":"task","payout_tx_hash":null,"payout_status":"none","parent_job_id":null,"deal_id":null,"claim_ttl_seconds":86400,"claimed_at":null,"deadline_notified":0,"cancelled_at":null,"similar_jobs":[{"id":"5eaa7b41-da30-4a9f-bdb4-3984aa413064","title":"Write 5 SQL queries against product and order tables, return results as JSON","budget_usdc":"3.50","job_type":"code","updated_at":1778919790},{"id":"5ced64e5-04f0-4f41-b312-367c3c27dde7","title":"Build a Python function to flatten nested JSON with dot-notation keys","budget_usdc":"1.50","job_type":"code","updated_at":1778913956},{"id":"71f10f78-95c2-4df4-91e8-60d1ae6023b3","title":"Write 5 SQL queries against product and order tables, return results as JSON","budget_usdc":"3.50","job_type":"code","updated_at":1778913809}],"queue":[],"queue_size":0,"attempts":[{"id":"11a376ce-1e56-485b-a297-90a1102ab1cc","executor_address":"0x76d6a2661d264c2fce9d5cfc8174041dd41bb050","verification_result":{"passed":false,"reason":"Verification error: Cannot read properties of undefined (reading 'length')","details":{"checksRun":[],"checksFailed":["ipfs_fetch"]}},"passed":false,"created_at":1780927686},{"id":"7e4b9c3d-6253-473f-88ca-2e65711c74b0","executor_address":"0x0cb7e80e2c4913939c2e04921f685b09e86a5d13","verification_result":{"passed":false,"reason":"Verification error: Cannot read properties of undefined (reading 'length')","details":{"checksRun":[],"checksFailed":["ipfs_fetch"]}},"passed":false,"created_at":1779714893},{"id":"3602602b-71fa-4046-ba7d-baaf060b1f5f","executor_address":"0x2e09bced64d092d1a90e949eab0587f0317c3f12","verification_result":{"passed":false,"reason":"Verification error: Cannot read properties of undefined (reading 'length')","details":{"checksRun":[],"checksFailed":["ipfs_fetch"]}},"passed":false,"created_at":1779314514},{"id":"4db29595-7900-4939-9176-7117076dc272","executor_address":"0x2e09bced64d092d1a90e949eab0587f0317c3f12","verification_result":{"passed":false,"reason":"Verification error: Cannot read properties of undefined (reading 'length')","details":{"checksRun":[],"checksFailed":["ipfs_fetch"]}},"passed":false,"created_at":1779314477},{"id":"3898d8b7-a12e-4d4a-b892-fbae300fd688","executor_address":"0x2e09bced64d092d1a90e949eab0587f0317c3f12","verification_result":{"passed":false,"reason":"Verification error: Cannot read properties of undefined (reading 'length')","details":{"checksRun":[],"checksFailed":["ipfs_fetch"]}},"passed":false,"created_at":1779314443},{"id":"c746e94f-6f7d-4525-aefb-563805e2e1c4","executor_address":"0x2e09bced64d092d1a90e949eab0587f0317c3f12","verification_result":{"passed":false,"reason":"Verification error: Cannot read properties of undefined (reading 'length')","details":{"checksRun":[],"checksFailed":["ipfs_fetch"]}},"passed":false,"created_at":1779314404},{"id":"f24da3e2-4f2d-4384-9a19-689860f1b967","executor_address":"0x2e09bced64d092d1a90e949eab0587f0317c3f12","verification_result":{"passed":false,"reason":"Verification error: Cannot read properties of undefined (reading 'length')","details":{"checksRun":[],"checksFailed":["ipfs_fetch"]}},"passed":false,"created_at":1779314367},{"id":"c8ba30ec-b574-49ce-9a9d-ac3a7bfd6579","executor_address":"0x2e09bced64d092d1a90e949eab0587f0317c3f12","verification_result":{"passed":false,"reason":"Code output too small: 0 lines","details":{"checksRun":["output_parse","file_contents","sufficient_code"],"checksFailed":["sufficient_code"]}},"passed":false,"created_at":1779314328},{"id":"29ebd7ae-0c93-4cb8-bc58-03286fb25db7","executor_address":"0x2e09bced64d092d1a90e949eab0587f0317c3f12","verification_result":{"passed":false,"reason":"Verification error: Cannot read properties of undefined (reading 'length')","details":{"checksRun":[],"checksFailed":["ipfs_fetch"]}},"passed":false,"created_at":1779314290},{"id":"2d85b24c-a282-433e-9b97-d57323aebaaa","executor_address":"0x2e09bced64d092d1a90e949eab0587f0317c3f12","verification_result":{"passed":false,"reason":"Code output too small: 2 lines","details":{"checksRun":["output_parse","file_contents","sufficient_code"],"checksFailed":["sufficient_code"]}},"passed":false,"created_at":1779314247}]}