' +
'');
scope.$eval();
expect(element.text()).toEqual('other');
scope.select = 1;
scope.$eval();
expect(element.text()).toEqual('one');
});
it("should match urls", function(){
var scope = angular.compile('
{{params.name}}
');
scope.url = '/Book/Moby';
scope.$init();
expect(scope.$element.text()).toEqual('Moby');
dealoc(scope);
});
it("should match sandwich ids", function(){
var scope = {};
var match = angular.widget('NG:SWITCH').route.call(scope, '/a/123/b', '/a/:id');
expect(match).toBeFalsy();
});
it('should call change on switch', function(){
var scope = angular.compile('
{{name}}
');
var cleared = false;
scope.url = 'a';
scope.$init();
expect(scope.name).toEqual(undefined);
expect(scope.$element.text()).toEqual('works');
dealoc(scope);
});
});
describe('ng:include', function(){
it('should include on external file and create a new child scope', function() {
var element = jqLite('');
var scope = angular.compile(element);
scope.counter = 0;
scope.url = 'myUrl';
scope.$service('$xhr.cache').data.myUrl = {value:'{{counter = counter + 1}}'};
scope.$init();
scope.$service('$browser').defer.flush();
expect(element.text()).toEqual('2');
//should also propagate evals to the child scope
scope.$eval();
expect(element.text()).toEqual('3');
dealoc(scope);
});
it('should include on external file and use an existing child scope', function() {
var element = jqLite('');
var scope = angular.compile(element);
scope.childScope = createScope();
scope.childScope.name = 'misko';
scope.url = 'myUrl';
scope.$service('$xhr.cache').data.myUrl = {value:'{{name}}'};
scope.$init();
scope.$service('$browser').defer.flush();
expect(element.text()).toEqual('misko');
dealoc(scope);
});
it('should remove previously included text if a falsy value is bound to src', function() {
var element = jqLite('');
var scope = angular.compile(element);
scope.childScope = createScope();
scope.childScope.name = 'igor';
scope.url = 'myUrl';
scope.$service('$xhr.cache').data.myUrl = {value:'{{name}}'};
scope.$init();
scope.$service('$browser').defer.flush();
expect(element.text()).toEqual('igor');
scope.url = undefined;
scope.$eval();
expect(element.text()).toEqual('');
dealoc(scope);
});
it('should allow this for scope', function(){
var element = jqLite('');
var scope = angular.compile(element);
scope.url = 'myUrl';
scope.$service('$xhr.cache').data.myUrl = {value:'{{c=c+1}}'};
scope.$init();
scope.$service('$browser').defer.flush();
// this one should really be just '1', but due to lack of real events things are not working
// properly. see discussion at: http://is.gd/ighKk
expect(element.text()).toEqual('2');
dealoc(element);
});
it('should evaluate onload expression when a partial is loaded', function() {
var element = jqLite('');
var scope = angular.compile(element);
expect(scope.loaded).not.toBeDefined();
scope.url = 'myUrl';
scope.$service('$xhr.cache').data.myUrl = {value:'my partial'};
scope.$init();
scope.$service('$browser').defer.flush();
expect(element.text()).toEqual('my partial');
expect(scope.loaded).toBe(true);
dealoc(element);
});
});
describe('a', function() {
it('should prevent default action to be executed when href is empty', function() {
var orgLocation = document.location.href,
preventDefaultCalled = false,
event;
compile('empty link');
if (msie) {
event = document.createEventObject();
expect(event.returnValue).not.toBeDefined();
element[0].fireEvent('onclick', event);
expect(event.returnValue).toEqual(false);
} else {
event = document.createEvent('MouseEvent');
event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, _null);
event.preventDefaultOrg = event.preventDefault;
event.preventDefault = function() {
preventDefaultCalled = true;
if (this.preventDefaultOrg) this.preventDefaultOrg();
};
element[0].dispatchEvent(event);
expect(preventDefaultCalled).toEqual(true);
}
expect(document.location.href).toEqual(orgLocation);
});
});
describe('@ng:repeat', function() {
it('should ng:repeat over array', function(){
var scope = compile('
');
scope.$set('items', {misko:'swe', shyam:'set'});
scope.$eval();
expect(element.text()).toEqual('misko:swe;shyam:set;');
});
it('should error on wrong parsing of ng:repeat', function(){
var scope = compile('
');
var log = "";
log += element.attr('ng-exception') + ';';
log += element.hasClass('ng-exception') + ';';
expect(log).toMatch(/Expected ng:repeat in form of 'item in collection' but got 'i dont parse'./);
});
it('should expose iterator offset as $index when iterating over arrays', function() {
var scope = compile('
');
scope.items = ['misko', 'shyam', 'frodo'];
scope.$eval();
expect(element.text()).toEqual('misko0|shyam1|frodo2|');
});
it('should expose iterator offset as $index when iterating over objects', function() {
var scope = compile('
');
scope.items = {'misko':'m', 'shyam':'s', 'frodo':'f'};
scope.$eval();
expect(element.text()).toEqual('misko:m0|shyam:s1|frodo:f2|');
});
it('should expose iterator position as $position when iterating over arrays', function() {
var scope = compile('
');
scope.items = ['misko', 'shyam', 'doug', 'frodo'];
scope.$eval();
expect(element.text()).toEqual('misko:first|shyam:middle|doug:middle|frodo:last|');
});
it('should expose iterator position as $position when iterating over objects', function() {
var scope = compile('
');
scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f'};
scope.$eval();
expect(element.text()).toEqual('misko:m:first|shyam:s:middle|doug:d:middle|frodo:f:last|');
});
});
describe('@ng:non-bindable', function() {
it('should prevent compilation of the owning element and its children', function(){
var scope = compile('
');
rootScope.$eval();
$browser.xhr.flush();
expect(partialScope.$element.text()).toEqual('4');
$location.updateHash('/bar');
$browser.xhr.expectGET('myUrl2').respond('angular is da best');
rootScope.$eval();
$browser.xhr.flush();
expect(partialScope.$element.text()).toEqual('angular is da best');
});
it('should remove all content when location changes to an unknown route', function() {
$route.when('/foo', {controller: angular.noop, template: 'myUrl1'});
$location.updateHash('/foo');
$browser.xhr.expectGET('myUrl1').respond('