angular.js/test/ScenarioSpec.js
Vojta Jina 988ed451b5 feat($browser): jQuery style url method, onUrlChange event
This is just basic implementation of $browser.url, $browser.onUrlChange methods:

$browser.url() - returns current location.href

$browser.url('/new') - set url to /new
If supported, history.pushState is used, location.href property otherwise.

$browser.url('/new', true) - replace current url with /new
If supported, history.replaceState is used, location.replace otherwise.

$browser.onUrlChange is only fired when url is changed from the browser:
- user types into address bar
- user clicks on back/forward button
- user clicks on link

It's not fired when url is changed using $browser.url()

Breaks Removed $browser.setUrl(), $browser.getUrl(), use $browser.url()
Breaks Removed $browser.onHashChange(), use $browser.onUrlChange()
2011-09-08 20:36:33 +02:00

48 lines
1.4 KiB
JavaScript

'use strict';
describe("ScenarioSpec: Compilation", function(){
var scope;
beforeEach(function(){
scope = null;
});
afterEach(function(){
dealoc(scope);
});
describe('compilation', function(){
it("should compile dom node and return scope", function(){
var node = jqLite('<div ng:init="a=1">{{b=a+1}}</div>')[0];
scope = angular.compile(node)();
scope.$digest();
expect(scope.a).toEqual(1);
expect(scope.b).toEqual(2);
});
it("should compile jQuery node and return scope", function(){
scope = compile(jqLite('<div>{{a=123}}</div>'))();
scope.$digest();
expect(jqLite(scope.$element).text()).toEqual('123');
});
it("should compile text node and return scope", function(){
scope = angular.compile('<div>{{a=123}}</div>')();
scope.$digest();
expect(jqLite(scope.$element).text()).toEqual('123');
});
});
describe("configuration", function(){
it("should take location object", function(){
var url = "http://server/#?book=moby";
scope = angular.compile("<div>{{$location}}</div>")();
var $location = scope.$service('$location');
var $browser = scope.$service('$browser');
expect($location.hashSearch.book).toBeUndefined();
$browser.url(url);
$browser.poll();
expect($location.hashSearch.book).toEqual('moby');
});
});
});