How do I add svg files via MatIconRegistry in unit tests?

前端 未结 6 2041
不思量自难忘°
不思量自难忘° 2021-02-05 10:16

I\'m currently implementing \'unit testing\' in my angular application. However, if I run them, I receive multiple warnings/errors similar to this one: \'Error retrieving

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 11:01

    Using typemoq for mocking; following worked for me:

    const mockIconRegistry = Mock.ofType();
    mockIconRegistry.setup(s => s.getNamedSvgIcon(It.isAny(), It.isAny())).returns(() => of(Mock.ofType().object));
    

    and then

    providers: [{ provide: MatIconRegistry, useFactory: () => mockIconRegistry.object }]
    

提交回复
热议问题