Skip to content

docs(aio): Testing: Description and code don't match #16064

Closed

Description

@andys8

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
The code example is a single line using subscribe:

this.route.params.subscribe(p => this.getHero(p && p['id']));

The description talks about the usage of pluck and forEach. They aren't used (probably anymore) in the code. This is misleading.

The expression after route.params chains an Observable operator that plucks the id from the params and then chains a forEach operator to subscribe to id-changing events. The id changes every time the user navigates to a different hero.
The forEach passes the new id value to the component's getHero method (not shown) which fetches a hero and sets the component's hero property. If the id parameter is missing, the pluck operator fails and the catch treats failure as a request to edit a new hero.

Screenshot

image

Expected behavior
The description should match the code. The description should be replaced or removed.

Affected Files
https://github.com/angular/angular/blob/master/aio/content/examples/testing/src/app/hero/hero-detail.component.ts
https://raw.githubusercontent.com/angular/angular/master/aio/content/guide/testing.md

Activity

  1. self-assigned this
    on Jun 21, 2017
  2. kapunahelewong commented on Feb 23, 2018

    @kapunahelewong
    Contributor

    @jenniferfell This issue might be resolved in #20697.

  3. added this to the needsTriage milestone on Feb 28, 2018
  4. jenniferfell commented on May 29, 2018

    @jenniferfell
    Contributor

    Closing. Doc and example were updated at some point to use paramMap.subscribe instead of the code above:

    ngOnInit(): void {
    // get hero when id param changes
    this.route.paramMap.subscribe(pmap => this.getHero(pmap.get('id')));
    }

    filename=https://angular.io/guide/testing

  5. angular-automatic-lock-bot commented on Sep 13, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  6. locked and limited conversation to collaborators on Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions