How to mock an activatedRoute parent Route in angular2 for testing purposes?

后端 未结 6 516
渐次进展
渐次进展 2020-12-05 03:57

Let\'s say I have this

export class QuestionnaireQuestionsComponent {

    questions: Question[] = [];
    private loading:boolean = true;


    constructor(         


        
6条回答
  •  生来不讨喜
    2020-12-05 04:34

    For scenarios in which you are reading the query params from the ActivatedRouteSnapshot like:

    this.someProperty = this.route.snapshot.data.query['paramKey'];
    

    The below code will be helpful in tests for feeding query params data into the route

    { 
      provide: ActivatedRoute, 
      useValue: {
        snapshot: {
          data: {
            query: {
              paramKey: 'paramValue'
            }
          }
        }
      }
    }
    

提交回复
热议问题