{"id":13495512,"url":"https://github.com/juristr/angular-testing-recipes","last_synced_at":"2025-04-05T01:08:31.883Z","repository":{"id":15473529,"uuid":"78220614","full_name":"juristr/angular-testing-recipes","owner":"juristr","description":"Simple testing patterns for Angular version 2+","archived":false,"fork":false,"pushed_at":"2023-01-03T19:51:43.000Z","size":1970,"stargazers_count":503,"open_issues_count":27,"forks_count":110,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-03-29T00:11:17.225Z","etag":null,"topics":["angular","jasmine","karma","testing"],"latest_commit_sha":null,"homepage":null,"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/juristr.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}},"created_at":"2017-01-06T16:25:30.000Z","updated_at":"2025-02-01T13:32:07.000Z","dependencies_parsed_at":"2023-01-11T20:23:26.109Z","dependency_job_id":null,"html_url":"https://github.com/juristr/angular-testing-recipes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juristr%2Fangular-testing-recipes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juristr%2Fangular-testing-recipes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juristr%2Fangular-testing-recipes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juristr%2Fangular-testing-recipes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juristr","download_url":"https://codeload.github.com/juristr/angular-testing-recipes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271532,"owners_count":20911587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","jasmine","karma","testing"],"created_at":"2024-07-31T19:01:35.446Z","updated_at":"2025-04-05T01:08:31.867Z","avatar_url":"https://github.com/juristr.png","language":"TypeScript","readme":"# Angular Testing Recipes\n\n[![Build Status](https://travis-ci.org/juristr/angular-testing-recipes.svg?branch=master)](https://travis-ci.org/juristr/angular-testing-recipes)\n\n\u003e This repo is for **Angular version 2+**. [More \u0026raquo;](https://juristr.com/blog/2016/12/let-me-explain-angular-release-cycles/)\n\nThe goal of this repository is to have a collection of recipes for common testing scenarios with Angular. I'm happy for every contribution/suggestion :smiley:.\n\n## Talk (Video + Slides)\n\nI've been giving a talk on \"Testing with Angular\".\n\n* [:notebook: Slides](https://docs.google.com/presentation/d/1gJCBr_M5dCcCX9WUM52ZUAKVlPj6hQv3MYXKlgFMpSA/edit?usp=sharing)\n* [:video_camera: Talk](https://www.youtube.com/watch?v=Uw_XomCJaGQ)\n\n## Contents\n\nAll the scenarios are listed here below and nicely linked to the source file.\n\n1.  [**Testing Components**](./src/app/components)\n    * [testing @Input](./src/app/components/input.component.spec.ts)  \n      _Learn how to test a component's `@Input()`._\n    * [testing @Output](./src/app/components/output.component.spec.ts)  \n      _Learn how to test a component's `@Output()`, more specifically the `EventEmitter` type._\n    * [testing timers inside components](./src/app/components/counter.component.spec.ts)  \n      _Learn about how to handle timers inside components using `fakeAsync` and `discardPeriodicTasks()`._\n    * [testing DOM manipulations](./src/app/components/domtesting.component.spec.ts)  \n      _Learn how to test the DOM manipulations which might be caused by like `*ngIf` statements etc._\n    * [testing content projection](./src/app/components/content-projection.component.spec.ts)  \n      _Learn how to test `\u003cng-content\u003e` directives._\n    * [testing dynamic CSS classes](./src/app/components/dynamic-css-classes.component.spec.ts)  \n      _Test CSS classes being added and removed dynamically from your component's template based on some conditional expressions._\n    * [testing dynamic CSS styles](./src/app/components/dynamic-styles.component.spec.ts)  \n      _Test dynamic CSS styles using custom Jasmine matchers._\n    * [mocking nested components](./src/app/components/nested.component.spec.ts)  \n      _Learn how to mock out nested components which you don't want to necessarily test_\n    * [testing component with service deps](./src/app/components/component-mock-external.component.spec.ts)  \n      _Simple test of component logic by manually instantiating the component_\n1.  [**Testing Services**](./src/app/services)\n    * [Simple stateless function](./src/app/services/greeting.service.spec.ts)  \n      _Learn about different ways of injecting a service into a test case as well as how to test service methods._\n    * [Async operations](./src/app/services/async.service.spec.ts)  \n      _Learn how to test async operations using the `async()` as well as `fakeAsync()` functions._\n    * [Mocking and remote http calls](./src/app/services/remote.service.spec.ts)\n      _Learn how to mock external dependencies, such as use the `MockBackend` provided by Angular to respond to http calls._\n    * [Mocking remote calls with Jasmine spies](./src/app/services/remote.service.fake-call.spec.ts)\n      _Fake the call by using Jasmine spies._\n1.  [**Testing Pipes**](./src/app/pipes)\n    * [custom filter pipe](./src/app/pipes/filter.pipe.spec.ts)\n    * [async pipes within templates](./src/app/components/async-stream.component.spec.ts)  \n      _Shows how to correctly resolve async pipes and then verify they properly render in the HTML_\n1.  [**Custom Matchers and Utilities**](./src/app/utils)\n    * [Create your own custom Jasmine matchers](./src/app/utils/custom-matchers.ts)\n\n## Articles on Testing\n\n* [:notebook: Angular 2 Testing Guide by Gerard Sans](https://medium.com/google-developer-experts/angular-2-testing-guide-a485b6cb1ef0)\n* [:notebook: Testing Angular Directives with Custom Matchers by Thoughtram](https://blog.thoughtram.io/angular/2016/12/27/angular-2-advance-testing-with-custom-matchers.html)\n* [:notebook: Essential Angular Testing by Nrwl](https://blog.nrwl.io/essential-angular-testing-192315f8be9b#.undqs5icx)\n* [:notebook: Three Ways to Test Angular 2 Components by Victor Savkin](https://vsavkin.com/three-ways-to-test-angular-2-components-dcea8e90bd8d#.hif9f24b5)\n\n## Run them yourself\n\nIf you want to run the example locally,\n\n1.  clone this repository\n1.  Run `npm install`\n1.  Run `npm test` to execute all the tests\n\nBy running `npm run test.watch` you can run the tests in watch mode which is particularly useful during development.\n\n## Contribute\n\nWanna help? Of course! Just open an [issue](https://github.com/juristr/angular-testing-recipes/issues) and/or [send me a PR](https://github.com/juristr/angular-testing-recipes/pulls) :smiley:.\n\n## Other Links \u0026 Resources\n\n* [Testing Angular Material Dialog templates](http://angular-tips.com/blog/2018/02/testing-angular-material-dialog-templates/)\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuristr%2Fangular-testing-recipes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuristr%2Fangular-testing-recipes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuristr%2Fangular-testing-recipes/lists"}