Tôi cố gắng để phạm vi truy cập của bộ điều khiển gắn liền với ** tùy chỉnh chỉ thị góc của tôi ** khi thử nghiệm trong hoa nhài.Nhận phạm vi điều khiển tùy chỉnh chỉ trong Jasmine kiểm tra
app.directive('MyDirective', function(){
return {
template:...,
scope:...,
controller: function($scope){
$scope.clickMe = function() {
....
};
$scope.message = "";
}
}
Tôi muốn viết thử nghiệm trong hoa nhài để xác minh xem phương thức clickMe có được xác định hay không.
it('should have 3 methods', function() {
expect(dscope).not.toBe(null);
expect(scope).not.toBe(null);
expect(angular.isFunction(dscope.clickMe)).toBe(true);
expect(dscope.message).toBe(true); }
Trong beforeEach() Tôi tuyên bố các biến phạm vi và dscope như sau:
beforeEach(inject(function( $rootScope, $compile){
scope = $rootScope.$new();
element = angular.element("<div my-directive></div>");
//bind the empty scope into the directive
$compile(element)(scope);
//access to internal directive scope of our element
dscope = element.scope(); }));
Nhưng khi tôi chạy thử nghiệm, tôi nhận được * và mong đợi "mong đợi sai lầm đến mức khó tin." không xác định được không null cho scope.message
Cảm ơn bạn rất nhiều! Tôi đã nổi giận với tất cả các ví dụ không hoạt động !! – achedeuzot
Cảm ơn câu hỏi & trả lời :) –