我有一个单元测试,它会给我一个错误:
未知提供者: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 :(得分:0)
您需要在控制器中注入$translate
,
像这样,
app.controller("YOUR_CONTROLLER_NAME", function($scope, $translate) {
// your code goes here
});
希望这有帮助!