Skip to content

bindToComponentInputs does not work when using RouterTestingModule #54461

Closed

Description

@wawyed

Which @angular/* package(s) are the source of the bug?

router

Is this a regression?

No

Description

it looks like the code in RouterTestingModule does not take into account bindToComponentInputs so having Input for resolvables results in failing unit tests even if you define the correct resolves in the route definition.

I'd expect something similar to RouterModule:

config?.bindToComponentInputs ? withComponentInputBinding().ɵproviders : [],

in https://github.com/angular/angular/blob/main/packages/router/testing/src/router_testing_module.ts#L88

export class RouterTestingModule {
  static withRoutes(
    routes: Routes,
    config?: ExtraOptions,
  ): ModuleWithProviders<RouterTestingModule> {
    return {
      ngModule: RouterTestingModule,
      providers: [
        {provide: ROUTES, multi: true, useValue: routes},
        {provide: ROUTER_CONFIGURATION, useValue: config ? config : {}},
        ...config?.bindToComponentInputs ? withComponentInputBinding().ɵproviders : [], <--- this is missing
      ],
    };
  }
}

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

No response

Anything else?

No response

Activity

  1. added this to the needsTriage milestone on Feb 15, 2024
  2. alxhub commented on Feb 15, 2024

    @alxhub
    Member

    RouterTestingModule does set up a specific configuration of the router. It's not strictly necessary - you can also use provideRouter() directly in your tests with whatever configuration you'd like.

  3. wawyed commented on Feb 15, 2024

    @wawyed
    Author

    But the fact still remains that RouterTestingModule has a second argument with router config which does include bindToComponentInputs, so I'd thought it should support such behaviour

  4. atscott commented on Feb 15, 2024

    @atscott
    Contributor

    As @alxhub mentioned, you can and should be using RouterModule or provideRouter directly in tests. RouterTestingModule is no longer needed or maintained so I've created a PR to officially deprecate it. The documentation was already updated to remove mentions of RouterTestingModule and the missing piece was the deprecation.

  5. added
    area: docs
    on Feb 15, 2024
  6. wawyed commented on Feb 15, 2024

    @wawyed
    Author

    I was not aware of that. I'll move to the new approach in that case.

    Thanks!

  7. added a commit that references this issue on Feb 20, 2024
    a9741e6
  8. angular-automatic-lock-bot commented on Mar 22, 2024

    @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.

  9. locked and limited conversation to collaborators on Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: docsarea: router

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions