Skip to content

RouterTestingModule should provide a way to set up snapshot data #15779

@juliemr

Description

@juliemr

Feature Request.

It would be nice to be able to set up route data and snapshots from the RouterTestingModule. The motivation here is something like a component which uses the route data in its init:

@Component({})
class MyComp {
  constructor(private route: ActivatedRoute) {};
  ngOnInit() {
    this.pizza = this.route.snapshot.data['pizza'];
  }
}

Currently, this can be tested by adding a provider to the TestBed to mock out ActivatedRoute, however it feels like something you should be able to do from the RouterTestingModule. Perhaps something like:

TestBed.configureTestingModule({
  imports: [
    RouterTestingModule.withRoutes([{
      path: '', // something to denote that this is the one that should be used?
      data: { pizzaToppings: ['mozzarella', 'onion', 'basil'] },
    }]),
  ],
});

cc @vikb, @vikerman

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions