How to unit test a component that depends on parameters from ActivatedRoute?

前端 未结 8 1111
离开以前
离开以前 2020-12-04 09:37

I am unit testing a component that is used to edit an object. The object has an unique id that is used in order to grab the specific object from an array of obj

8条回答
  •  情深已故
    2020-12-04 10:05

    Here is how I tested it in angular 2.0 latest...

    import { ActivatedRoute, Data } from '@angular/router';
    

    and in Providers section

    {
      provide: ActivatedRoute,
      useValue: {
        data: {
          subscribe: (fn: (value: Data) => void) => fn({
            yourData: 'yolo'
          })
        }
      }
    }
    

提交回复
热议问题