2017-07-18 79 views
0

我有一個單元測試,引發我一個錯誤:角1 /茉莉花 - 未知提供商:translateFilterProvider < - translateFilter

未知提供商:translateFilterProvider < - translateFilter

這個服務$翻譯?如果這就是我可以注入它,或者你有解決方案?

import angular from 'angular' 
import 'angular-mocks' 

let $scope 
let $compile 
let htmlElement 

describe('ProjectGeneralSituationForm',() => { 
    beforeEach(angular.mock.module('ProjectGeneralSituationModule')) 

    beforeEach(() => { 
    inject((_$rootScope_, _$compile_) => { 
     $scope = _$rootScope_.$new() 
     $compile = _$compile_ 
    }) 
    }) 

    beforeEach(() => { 
    $scope.project = {} 
    $scope.projectTypes = {} 
    $scope.projectReferences = {} 
    htmlElement = $compile(`<project-general-situation-form project="project" project-types="projectTypes" project-references="projectReferences"></project-general-situation-form>`)($scope) 
    $scope.$digest() 
    }) 

    it('should be defined',() => { 
    expect(htmlElement).toBeDefined() 
    }) 
}) 
+0

是一個指令?的測試,所以試試這裏inject((_ _rootScope_,_ $ compile_,_ $ translate_) –

回答

0

你需要注入在控制器$translate

這樣,

app.controller("YOUR_CONTROLLER_NAME", function($scope, $translate) { 
    // your code goes here 
}); 

希望這有助於!

相關問題