angular/packages/examples
Andrew Scott dedac8d3f7 feat(router): Add test helper for trigger navigations in tests (#48552)
In order to test components and services which depend on router navigations, such as `ActivatedRoute` instances, tests currently need to provide a fair bit of boilerplate _or_ they can set up a stub for `ActivatedRoute` and list it in the `providers` to override it in `TestBed`. This approach of stubbing the `ActivatedRoute` creates a situation that can easily cause the test to break. The stub often only mocks out the dependencies that the component/service _currently_ needs. This dependencies might change over time and break the test in an unexpected way. In addition, it is difficult to get the structure of `ActivatedRoute` exactly correct.

This change will allow unit tests to quickly set up routes, trigger real navigations in the Router, and get instances of component's to test along with real instances of `ActivatedRoute`. This all comes without needing to know that the component depends on `ActivatedRoute` at all. This becomes more important when considering that a component may be refactored in the future to use `@Input` rather than access data on the `ActivatedRoute` instance (see #18967). Tests which mock out `ActivatedRoute` would all break, but those which use `navigateForTest` would continue to work without needing any updates.

resolves #15779
resolves #48608

PR Close #48552
2023-01-25 19:31:38 +00:00
..
common refactor: switch packages/examples to ESM-compatible http server (#48521) 2022-12-19 19:50:44 +00:00
core refactor: switch packages/examples to ESM-compatible http server (#48521) 2022-12-19 19:50:44 +00:00
forms refactor: switch packages/examples to ESM-compatible http server (#48521) 2022-12-19 19:50:44 +00:00
http build: switch example e2e tests to bazel (#28402) 2019-01-28 19:21:09 -08:00
platform-browser build(bazel): add bazel targets for aio doc generation 2022-11-22 13:51:16 -07:00
router feat(router): Add test helper for trigger navigations in tests (#48552) 2023-01-25 19:31:38 +00:00
service-worker refactor: switch packages/examples to ESM-compatible http server (#48521) 2022-12-19 19:50:44 +00:00
test-utils build: remove remaining usages of deprecated ts_devserver (#48521) 2022-12-19 19:50:44 +00:00
testing build(bazel): add bazel targets for aio doc generation 2022-11-22 13:51:16 -07:00
upgrade refactor: switch packages/examples to ESM-compatible http server (#48521) 2022-12-19 19:50:44 +00:00
BUILD.bazel build: switch example e2e tests to bazel (#28402) 2019-01-28 19:21:09 -08:00
index.html refactor: switch packages/examples to ESM-compatible http server (#48521) 2022-12-19 19:50:44 +00:00
README.md build: switch example e2e tests to bazel (#28402) 2019-01-28 19:21:09 -08:00
tsconfig-e2e.json build: switch example e2e tests to bazel (#28402) 2019-01-28 19:21:09 -08:00

API Examples

This folder contains small example apps that get in-lined into our API docs. Each example contains tests for application behavior (as opposed to testing Angular's behavior) just like an Angular application developer would write.

Running the examples

# Serving individual examples (e.g. common)
yarn bazel run //packages/examples/common:devserver

# "core" examples
yarn bazel run //packages/examples/core:devserver

Running the tests

yarn bazel test //packages/examples/...