测试
describe('testModule', function () {
// beforeEach(module('testApp'));
beforeEach(module('testApp', function($provide){
}));
var $compile, $controller;
beforeEach(inject(function(_$compile_, _$controller_){
$compile = _$compile_;
$controller = _$controller_;
}));
describe('tests', function () {
// directive test ??????????
it('name test', function () {
var $scope = {};
var controller = $controller('testController', { $scope: $scope });
expect($scope.name).toBe("pikachu");
});
}
);
});
app
var testApp = angular.module('testApp', ['testModule']);
angular.module('testModule')
.component('testModule', {
template: '<input type="text" ng-model="name" />',
controller: [
'$scope',
function testController($scope){
$scope.name = "pikachu";
}
]
});
我可以测试控制器和服务,但无法测试任何指令。我应该在“ it”函数中写些什么来测试输入是否符合预期?谢谢。我找不到任何可行的示例。互联网上的每个示例在测试ng指令时都会给出另一个错误。