The simplest way to do this is to just use the useValue
attribute and provide an Observable of the value you want to mock.
RxJS < 6
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
...
{
provide: ActivatedRoute,
useValue: {
params: Observable.of({id: 123})
}
}
RxJS >= 6
import { of } from 'rxjs';
...
{
provide: ActivatedRoute,
useValue: {
params: of({id: 123})
}
}
Related Contents:
- Angular 2 unit testing components with routerLink
- Updating input html field from within an Angular 2 test
- Any way to test EventEmitter in Angular2?
- Angular 2: 404 error occur when I refresh through the browser [duplicate]
- What’s the difference between faking, mocking, and stubbing?
- What’s the difference between unit tests and integration tests? [duplicate]
- Show loading screen when navigating between routes in Angular 2
- What is unit testing? [closed]
- Warn user of unsaved changes before leaving page
- How to get current route
- Angular2 multiple router-outlet in the same template
- Should one test internal implementation, or only test public behaviour?
- Passing data into “router-outlet” child components
- Angular 2 router event listener
- Unit test naming best practices [closed]
- In Angular, how do you determine the active route?
- Angular2 canActivate() calling async function
- Change route params without reloading in Angular 2
- angular 2 disable url encoding
- What are the differences between unit tests, integration tests, smoke tests, and regression tests? [closed]
- How to RowTest with MSTest?
- Unit Tests not discovered in Visual Studio 2017
- How can I unit test a component that uses the Router in Angular?
- How to terminate a program when it crashes? (which should just fail a unit test instead of getting stuck forever)
- How to handle query parameters in angular 2
- Angular 2 – How do I navigate to another route using this.router.parent.navigate(‘/about’)?
- Any suggestions for testing extjs code in a browser, preferably with selenium?
- Unit testing Anti-patterns catalogue
- Mocking $modal in AngularJS unit tests
- Angular2 – Interaction between components using a service
- Dynamic routing based on external data
- How to switch layouts in Angular2
- Configuring IntelliJ IDEA for unit testing with JUnit
- Is Angular 2’s Router broken when using HTML5 routes? [duplicate]
- How to test Spring Data repositories?
- What is the best way to unit-test SLF4J log messages?
- How do I navigate to a sibling route?
- Junit5 mock a static method
- Get route query params
- How to unit test a Go Gin handler function?
- Redirect to a different component inside @CanActivate in Angular2
- Run JUnit tests with SBT
- Angular 2 different components with same route
- Proper package naming for testing with the Go language
- How can I unit test a GUI?
- Example invalid utf8 string?
- Angular 2 – Routing – CanActivate work with Observable
- Is there an easy way to stub out time.Now() globally during test?
- Why should unit tests test only one thing?
- When is a Test not a Unit-test?