我使用 teaspoon 作为测试运行器,它加载所有模板文件(使用 angular-rails-templates),它templates
用如下内容填充模块:
angular.module("templates").run(["$templateCache", function($templateCache) {
$templateCache.put("directives/sample/tmpl.html", '<span>Hey</span>')
}]);
我的指令咖啡是这样的:
angular.module 'myApp'
.directive 'sample', () ->
restrict: 'E'
templateUrl: 'directives/sample/tmpl.html'
scope:
address: "="
controllerAs: 'vm'
bindToController: true
controller: () ->
还有我的测试咖啡
describe "sample directive", ->
element = undefined
beforeEach ->
module("myApp", "templates")
# Store references to $rootScope and $compile
# so they are available to all tests in this describe block
beforeEach ->
inject ($compile, $rootScope) ->
scope = $rootScope.$new()
scope.address = "abcdef"
element = $compile("<div><sample address='address'/></div>")(scope)
scope.$digest()
it "Replaces the element with the appropriate content", ->
expect(element.html()).toContain "Hey"
该指令将永远不会与此一起呈现。如果我将 templateUrl 替换为模板内容,那么它运行良好。但这根本没有用。在使用 templateUrl 进行测试期间让指令呈现我缺少什么?