【发布时间】:2014-06-11 17:42:51
【问题描述】:
我有一个开始的指令
angular.module('App')
.directive('pong', function ($window) {
然后我将如何在测试中模拟 $window?我在想一些这样的东西,但不确定在哪里通过模拟的 $window。
// Initialize the controller and a mock scope
beforeEach(inject(function ($injector, $rootScope) {
scope = $rootScope.$new();
scope.testValue = null;
$window = $injector.get('$window');
}));
function compileDirective(tpl) {
if (!tpl) {
tpl = '<button pong="{{testValue}}">Test</button>';
}
inject(function($compile) {
element = $compile(tpl)(scope);
});
scope.$digest();
}
【问题讨论】:
标签: angularjs angularjs-directive