How to mock angular translate filter in unit tests for directives

前端 未结 4 931
说谎
说谎 2020-12-05 14:29

In my directive templates, I need to use the angular translate filter as such:

    
4条回答
  •  一向
    一向 (楼主)
    2020-12-05 14:53

    This is the ES6 way:

    beforeEach(angular.mock.module('myModule'), ($provide) => {
        $provide.value('$translate', t => ({ then: cb => cb(t) }));
    }));   
    

    This does not mock the $translate.instant method. For this you could assign the function to a variable and then assign the angular.identity method to the instantproperty.

提交回复
热议问题