mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
added few extra tests
This commit is contained in:
parent
d934054cfc
commit
1990cbbf28
3 changed files with 98 additions and 4 deletions
|
|
@ -110,7 +110,7 @@ function inputWidget(events, modelAccessor, viewAccessor, initValue) {
|
|||
this.$eval(element.attr('ng-init')||'');
|
||||
element.bind(events, function(){
|
||||
model.set(view.get());
|
||||
scope.$eval(action);
|
||||
scope.$tryEval(action, element);
|
||||
});
|
||||
scope.$watch(model.get, view.set);
|
||||
};
|
||||
|
|
|
|||
90
test/ScopeSpec.js
Normal file
90
test/ScopeSpec.js
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
describe('scope/model', function(){
|
||||
|
||||
it('should create a scope with parent', function(){
|
||||
var model = scope({name:'Misko'});
|
||||
expect(model.name).toEqual('Misko');
|
||||
});
|
||||
|
||||
it('should have $get/set$/parent$', function(){
|
||||
var parent = {};
|
||||
var model = scope(parent);
|
||||
model.$set('name', 'adam');
|
||||
expect(model.name).toEqual('adam');
|
||||
expect(model.$get('name')).toEqual('adam');
|
||||
expect(model.$parent).toEqual(parent);
|
||||
});
|
||||
|
||||
//$eval
|
||||
it('should eval function with correct this and pass arguments', function(){
|
||||
var model = scope();
|
||||
model.$eval(function(name){
|
||||
this.name = name;
|
||||
}, 'works');
|
||||
expect(model.name).toEqual('works');
|
||||
});
|
||||
|
||||
it('should eval expression with correct this', function(){
|
||||
var model = scope();
|
||||
model.$eval('name="works"');
|
||||
expect(model.name).toEqual('works');
|
||||
});
|
||||
|
||||
//$onEval
|
||||
it('should watch an expression for change', function(){
|
||||
var model = scope();
|
||||
model.oldValue = "";
|
||||
var count = 0;
|
||||
model.name = 'adam';
|
||||
model.$watch('name', function(){ count ++; });
|
||||
model.$watch(function(){return model.name;}, function(newValue, oldValue){
|
||||
this.newValue = newValue;
|
||||
this.oldValue = oldValue;
|
||||
});
|
||||
model.name = 'misko';
|
||||
model.$eval();
|
||||
expect(count).toEqual(1);
|
||||
expect(model.newValue).toEqual('misko');
|
||||
expect(model.oldValue).toEqual('adam');
|
||||
});
|
||||
|
||||
it('should eval with no arguments', function(){
|
||||
var model = scope();
|
||||
var count = 0;
|
||||
model.$onEval(function(){count++;});
|
||||
model.$eval();
|
||||
expect(count).toEqual(1);
|
||||
});
|
||||
|
||||
//$bind
|
||||
it('should curry a function with respect to scope', function(){
|
||||
var model = scope();
|
||||
model.name = 'misko';
|
||||
expect(model.$bind(function(){return this.name;})()).toEqual('misko');
|
||||
});
|
||||
|
||||
//$behavior
|
||||
it('should behave as class', function(){
|
||||
function Printer(brand){
|
||||
this.brand = brand;
|
||||
};
|
||||
Printer.prototype.print = function(){
|
||||
this.printed = true;
|
||||
};
|
||||
var model = scope({ name: 'parent' }, Printer, 'hp');
|
||||
expect(model.brand).toEqual('hp');
|
||||
model.print();
|
||||
expect(model.printed).toEqual(true);
|
||||
});
|
||||
|
||||
|
||||
|
||||
//$tryEval
|
||||
it('should report error on element', function(){
|
||||
|
||||
});
|
||||
|
||||
it('should report error on visible element', function(){
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -172,15 +172,19 @@ describe("input widget", function(){
|
|||
});
|
||||
|
||||
it('should report error on missing field', function(){
|
||||
//compile('<input type="text"/>');
|
||||
compile('<input type="text"/>');
|
||||
expect(element.hasClass('ng-exception')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should report error on assignment error', function(){
|
||||
|
||||
compile('<input type="text" name="1-2" value="x"/>');
|
||||
expect(element.hasClass('ng-exception')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should report error on ng-action exception', function(){
|
||||
|
||||
compile('<button ng-action="a-2=x">click</button>');
|
||||
element.click();
|
||||
expect(element.hasClass('ng-exception')).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue