{"id":25591389,"url":"https://github.com/bobbyg603/ng-testing-tips-first-value-from","last_synced_at":"2026-05-17T18:13:44.786Z","repository":{"id":180445329,"uuid":"610082338","full_name":"bobbyg603/ng-testing-tips-first-value-from","owner":"bobbyg603","description":"Angular Testing Tips: FirstValueFrom companion repo","archived":false,"fork":false,"pushed_at":"2023-03-11T23:18:30.000Z","size":248,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-08T04:54:05.283Z","etag":null,"topics":["angular","observables","promises","rxjs","testing","typescript"],"latest_commit_sha":null,"homepage":"https://medium.com/javascript-in-plain-english/angular-testing-tips-firstvaluefrom-e861fe05ba1e","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bobbyg603.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-06T03:37:16.000Z","updated_at":"2023-03-11T23:19:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"34ce25a5-53dd-4360-8be8-ce00ca51ca84","html_url":"https://github.com/bobbyg603/ng-testing-tips-first-value-from","commit_stats":null,"previous_names":["bobbyg603/ng-testing-tips-first-value-from"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bobbyg603/ng-testing-tips-first-value-from","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbyg603%2Fng-testing-tips-first-value-from","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbyg603%2Fng-testing-tips-first-value-from/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbyg603%2Fng-testing-tips-first-value-from/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbyg603%2Fng-testing-tips-first-value-from/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bobbyg603","download_url":"https://codeload.github.com/bobbyg603/ng-testing-tips-first-value-from/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbyg603%2Fng-testing-tips-first-value-from/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33149523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T09:28:26.183Z","status":"ssl_error","status_checked_at":"2026-05-17T09:27:52.702Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","observables","promises","rxjs","testing","typescript"],"created_at":"2025-02-21T09:51:15.469Z","updated_at":"2026-05-17T18:13:44.756Z","avatar_url":"https://github.com/bobbyg603.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![angular-testing-tips-first-value-from](https://user-images.githubusercontent.com/2646053/224515096-ec52023f-a146-48bf-b1dc-5e94a317b86f.png)\n\n# Angular Testing Tips: FirstValueFrom\n\nThis repo demonstrates how to use the RxJS helper FirstValueFrom to write better Angular unit tests. A companion article for this repo can be found on Medium.\n\n## Steps 🥾\n\nClone or fork this repo\n\n```bash\ngit clone https://github.com/bobbyg603/ng-testing-tips-first-value-from\n```\n\nInstall the dependencies\n\n```bash\ncd ng-testing-tips-first-value-from \u0026\u0026 npm i \n```\n\nRun the app and the affirmations server\n\n```bash\nnpm run start\n```\n\nRun the tests\n\n```bash\nnpm test\n```\n\n## Examples 🧑‍🏫\n\nHere's a super succinct example of how to use [firstValueFrom](https://rxjs.dev/api/index/function/firstValueFrom) and [expectAsync](https://jasmine.github.io/api/4.5/global.html#expectAsync) to verify a value emitted by an observable.\n\n[affirmations.component.spec.ts](https://github.com/bobbyg603/ng-testing-tips-first-value-from/blob/bca93941c464cf40d6e94d457783c1f214551b51/src/app/affirmations/affirmations.component.spec.ts#L37-L39)\n```ts\nit('should start with \\'Loading...\\'', () =\u003e \n  expectAsync(firstValueFrom(component.affirmation$)).toBeResolvedTo('Loading...')\n);\n```\n\nYou can test verify a value is emitted by an output by saving the promise returned by firstValueFrom and awaiting it later.\n\n[counter.component.spec.ts](https://github.com/bobbyg603/ng-testing-tips-first-value-from/blob/bca93941c464cf40d6e94d457783c1f214551b51/src/app/counter/counter.component.spec.ts#L25-L35)\n```ts\nit('should emit updated count', async () =\u003e {\n  const newCount = 3;\n  const resultPromise = firstValueFrom(component.countChange);\n  \n  component.onCountChange(newCount);\n  const result = await resultPromise;\n\n  expect(result).toEqual(newCount);\n});\n```\n\nWe can use [skip](https://rxjs.dev/api/index/function/skip) to verify the next value emitted by an observable.\n\n[counter.component.spec.ts](https://github.com/bobbyg603/ng-testing-tips-first-value-from/blob/bca93941c464cf40d6e94d457783c1f214551b51/src/app/counter/counter.component.spec.ts#L37-L50)\n```ts\nit('should emit count each time onCountChange is called', async () =\u003e {\n  const values = [1, 2];\n  const firstResultPromise = firstValueFrom(component.countChange);\n  const secondResultPromise = firstValueFrom(component.countChange.pipe(skip(1)));\n\n  values.forEach(value =\u003e component.onCountChange(value));\n  const firstResult = await firstResultPromise;\n  const secondResult = await secondResultPromise;\n\n  expect(firstResult).toEqual(values[0]);\n  expect(secondResult).toEqual(values[1]);\n});\n```\n\nA sequence of values emitted by an observable can be captured as an array using [take](https://rxjs.dev/api/operators/take) and [toArray](https://rxjs.dev/api/index/function/toArray).\n\n[counter.component.spec.ts](https://github.com/bobbyg603/ng-testing-tips-first-value-from/blob/bca93941c464cf40d6e94d457783c1f214551b51/src/app/counter/counter.component.spec.ts#L52-L68)\n```ts\nit('should emit count each time onCountChange is called', async () =\u003e {\n  const values = [1, 2, 3];\n  const resultPromise = firstValueFrom(\n    component.countChange\n      .pipe(\n        take(values.length),\n        toArray()\n      )\n  );\n  \n  values.forEach(value =\u003e component.onCountChange(value));\n  const result = await resultPromise;\n  \n  expect(result).toEqual(jasmine.arrayContaining(values));\n});\n```\n\nIf you found this repo valuable please subscribe to [@bobbyg603 on Medium](https://medium.com/@bobbyg603) for more Angular tips and tricks. \n\nThanks for reading! \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobbyg603%2Fng-testing-tips-first-value-from","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbobbyg603%2Fng-testing-tips-first-value-from","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobbyg603%2Fng-testing-tips-first-value-from/lists"}