diff options
| author | Misko Hevery | 2010-04-03 17:04:36 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-04-03 17:04:36 -0700 |
| commit | a80a61839a66d244c8bb14bbe2975746e02516c8 (patch) | |
| tree | 5a7b4d9d3e2a7a15ebf55e068782fbf2aa4ac6bf /test | |
| parent | 35ca4fcb9c49e505e28669e951e01ddedb01d7db (diff) | |
| download | angular.js-a80a61839a66d244c8bb14bbe2975746e02516c8.tar.bz2 | |
injection is now working
Diffstat (limited to 'test')
| -rw-r--r-- | test/BinderTest.js | 5 | ||||
| -rw-r--r-- | test/BrowserTest.js (renamed from test/UrlWatcherTest.js) | 10 | ||||
| -rw-r--r-- | test/CompilerSpec.js | 62 | ||||
| -rw-r--r-- | test/FormattersTest.js | 22 | ||||
| -rw-r--r-- | test/ParserTest.js | 2 | ||||
| -rw-r--r-- | test/ScopeSpec.js | 57 | ||||
| -rw-r--r-- | test/servicesSpec.js | 17 | ||||
| -rw-r--r-- | test/testabilityPatch.js | 30 |
8 files changed, 108 insertions, 97 deletions
diff --git a/test/BinderTest.js b/test/BinderTest.js index 9c5c5dc6..fa3127d7 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -19,6 +19,7 @@ BinderTest.prototype.tearDown = function(){ if (this.element && this.element.dealoc) this.element.dealoc(); }; + BinderTest.prototype.testChangingTextfieldUpdatesModel = function(){ var state = this.compile('<input type="text" name="model.price" value="abc">', {model:{}}); state.scope.$eval(); @@ -707,7 +708,7 @@ BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = f var second = jqLite(c.node[0].childNodes[1]); first.click(); - assertEquals("ABC", c.scope.$get('greeting')); + assertEquals("ABC", c.scope.greeting); second.click(); assertTrue(second.hasClass("ng-exception")); @@ -821,5 +822,3 @@ BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ binder.updateView(); assertEquals(binder.location.get(), "a#a=b"); }; - - diff --git a/test/UrlWatcherTest.js b/test/BrowserTest.js index 6080ca62..2e630172 100644 --- a/test/UrlWatcherTest.js +++ b/test/BrowserTest.js @@ -1,11 +1,11 @@ -UrlWatcherTest = TestCase('UrlWatcherTest'); +BrowserTest = TestCase('BrowserTest'); -UrlWatcherTest.prototype.testUrlWatcher = function () { +BrowserTest.prototype.testUrlWatcher = function () { expectAsserts(2); var location = {href:"http://server", hash:""}; - var watcher = new UrlWatcher(location); + var watcher = new Browser(location); watcher.delay = 1; - watcher.watch(function(url){ + watcher.watchUrl(function(url){ assertEquals('http://getangular.test', url); }); watcher.setTimeout = function(fn, delay){ @@ -15,7 +15,7 @@ UrlWatcherTest.prototype.testUrlWatcher = function () { }; fn(); }; - watcher.start(); + watcher.startUrlWatcher(); }; FunctionTest = TestCase("FunctionTest"); diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 59b7ab6b..9922070f 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -1,8 +1,4 @@ -xdescribe('compiler', function(){ - function element(html) { - return jQuery(html)[0]; - } - +describe('compiler', function(){ var compiler, textMarkup, directives, widgets, compile, log; beforeEach(function(){ @@ -29,25 +25,25 @@ xdescribe('compiler', function(){ widgets = {}; compiler = new Compiler(textMarkup, attrMarkup, directives, widgets); compile = function(html){ - var e = element("<div>" + html + "</div>"); - var view = compiler.compile(e)(e); - view.init(); - return view.scope; + var e = jqLite("<div>" + html + "</div>"); + var scope = compiler.compile(e)(e); + scope.$init(); + return scope; }; }); it('should recognize a directive', function(){ - var e = element('<div directive="expr" ignore="me"></div>'); + var e = jqLite('<div directive="expr" ignore="me"></div>'); directives.directive = function(expression, element){ log += "found"; expect(expression).toEqual("expr"); - expect(element[0]).toEqual(e); + expect(element).toEqual(e); return function initFn() { log += ":init"; }; }; var template = compiler.compile(e); - var init = template(e).init; + var init = template(e).$init; expect(log).toEqual("found"); init(); expect(log).toEqual("found:init"); @@ -61,13 +57,13 @@ xdescribe('compiler', function(){ it('should watch scope', function(){ var scope = compile('<span watch="name"/>'); expect(log).toEqual(""); - scope.updateView(); - scope.set('name', 'misko'); - scope.updateView(); - scope.updateView(); - scope.set('name', 'adam'); - scope.updateView(); - scope.updateView(); + scope.$eval(); + scope.$set('name', 'misko'); + scope.$eval(); + scope.$eval(); + scope.$set('name', 'adam'); + scope.$eval(); + scope.$eval(); expect(log).toEqual(":misko:adam"); }); @@ -83,29 +79,17 @@ xdescribe('compiler', function(){ element.removeAttr("duplicate"); var template = this.compile(element); return function(marker) { - this.$addEval(function() { + this.$onEval(function() { marker.after(template(element.clone()).element); }); }; }; var scope = compile('before<span duplicate="expr">x</span>after'); - expect($(scope.element).html()).toEqual('before<!--marker-->after'); - scope.updateView(); - expect($(scope.element).html()).toEqual('before<!--marker--><span>x</span>after'); - scope.updateView(); - expect($(scope.element).html()).toEqual('before<!--marker--><span>x</span><span>x</span>after'); - }); - - it('should allow for exculsive tags which suppress others', function(){ - directives.exclusive = function(){ - return function() { - log += ('exclusive'); - }; - }; - directives.exclusive.exclusive = true; - - compile('<span hello="misko", exclusive/>'); - expect(log).toEqual('exclusive'); + expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment>after</div>'); + scope.$eval(); + expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment>after</div>'); + scope.$eval(); + expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment>after</div>'); }); it('should process markup before directives', function(){ @@ -117,7 +101,7 @@ xdescribe('compiler', function(){ } }); var scope = compile('before<span>middle</span>after'); - expect(scope.element.innerHTML).toEqual('before<span hello="middle">replaced</span>after'); + expect(scope.$element[0].innerHTML).toEqual('before<span hello="middle">replaced</span>after'); expect(log).toEqual("hello middle"); }); @@ -129,7 +113,7 @@ xdescribe('compiler', function(){ }; }; var scope = compile('<ng:button>push me</ng:button>'); - expect(scope.element.innerHTML).toEqual('<div>button</div>'); + expect(scope.$element[0].innerHTML).toEqual('<div>button</div>'); expect(log).toEqual('init'); }); diff --git a/test/FormattersTest.js b/test/FormattersTest.js index 59f12c1f..b520faf9 100644 --- a/test/FormattersTest.js +++ b/test/FormattersTest.js @@ -4,7 +4,7 @@ TestCase("formatterTest", { assertEquals("xyz", angular.formatter.noop.parse("xyz")); assertEquals(null, angular.formatter.noop.parse(null)); }, - + testList: function() { assertEquals('a, b', angular.formatter.list.format(['a', 'b'])); assertEquals('', angular.formatter.list.format([])); @@ -12,26 +12,26 @@ TestCase("formatterTest", { assertEquals([], angular.formatter.list.parse("")); assertEquals([], angular.formatter.list.parse(null)); }, - + testBoolean: function() { - assertEquals('true', angular.formatter.boolean.format(true)); - assertEquals('false', angular.formatter.boolean.format(false)); - assertEquals(true, angular.formatter.boolean.parse("true")); - assertEquals(false, angular.formatter.boolean.parse("")); - assertEquals(false, angular.formatter.boolean.parse("false")); - assertEquals(null, angular.formatter.boolean.parse(null)); + assertEquals('true', angular.formatter['boolean'].format(true)); + assertEquals('false', angular.formatter['boolean'].format(false)); + assertEquals(true, angular.formatter['boolean'].parse("true")); + assertEquals(false, angular.formatter['boolean'].parse("")); + assertEquals(false, angular.formatter['boolean'].parse("false")); + assertEquals(null, angular.formatter['boolean'].parse(null)); }, - + testNumber: function() { assertEquals('1', angular.formatter.number.format(1)); assertEquals(1, angular.formatter.number.format('1')); }, - + testTrim: function() { assertEquals('', angular.formatter.trim.format(null)); assertEquals('', angular.formatter.trim.format("")); assertEquals('a', angular.formatter.trim.format(" a ")); assertEquals('a', angular.formatter.trim.parse(' a ')); } - + }); diff --git a/test/ParserTest.js b/test/ParserTest.js index 639e919f..6170dd4a 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -171,7 +171,7 @@ ParserTest.prototype.testComparison = function(){ assertEquals(scope.$eval("1>2"), 1>2); assertEquals(scope.$eval("2>=1"), 2>=1); - assertEquals(true==2<3, scope.$eval("true==2<3")); + assertEquals(true === 2<3, scope.$eval("true==2<3")); }; diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 8d2a0ed4..a7322cae 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -65,20 +65,6 @@ describe('scope/model', function(){ 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 = createScope({ name: 'parent' }, Printer, 'hp'); - expect(model.brand).toEqual('hp'); - model.print(); - expect(model.printed).toEqual(true); - }); - //$tryEval it('should report error on element', function(){ var scope = createScope(); @@ -108,16 +94,6 @@ describe('scope/model', function(){ expect(scope.log).toEqual('first;middle;last;'); }); - // Services are initialized - it("should inject services", function(){ - var scope = createScope(serviceAdapter({ - $window: function(){ - return window; - } - })); - expect(scope.$window).toEqual(window); - }); - it("should have $root and $parent", function(){ var parent = createScope(); var scope = createScope(parent); @@ -125,4 +101,37 @@ describe('scope/model', function(){ expect(scope.$parent).toEqual(parent); }); + // Service injection + it('should inject services', function(){ + var scope = createScope(null, { + service:function(){ + return "ABC"; + } + }); + expect(scope.service).toEqual("ABC"); + }); + + it('should inject arugments', function(){ + var scope = createScope(null, { + name:function(){ + return "misko"; + }, + greet: extend(function(name) { + return 'hello ' + name; + }, {inject:['name']}) + }); + expect(scope.greet).toEqual("hello misko"); + }); + + it('should throw error on missing dependency', function(){ + try { + createScope(null, { + greet: extend(function(name) { + }, {inject:['name']}) + }); + } catch(e) { + expect(e).toEqual("Don't know how to inject 'name'."); + } + }); + }); diff --git a/test/servicesSpec.js b/test/servicesSpec.js index b92975d0..49000af4 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -2,11 +2,7 @@ describe("services", function(){ var scope; beforeEach(function(){ - scope = createScope({ - $config: { - 'location': {'get':noop, 'set':noop, 'watch':noop} - } - }, serviceAdapter(angularService)); + scope = createScope(null, angularService, {}); }); it("should inject $window", function(){ @@ -46,4 +42,15 @@ describe("services", function(){ expect(scope.$location()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html'); }); + xit('should add stylesheets', function(){ + scope.$document = { + getElementsByTagName: function(name){ + expect(name).toEqual('LINK'); + return []; + } + }; + scope.$document.addStyleSheet('css/angular.css'); + + }); + }); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 86d139cf..752f8ef2 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -3,7 +3,7 @@ dump = bind(jstd.console, jstd.console.log); function nakedExpect(obj) { return expect(angular.fromJson(angular.toJson(obj))); -}; +} swfobject = { createSwf:function() { @@ -27,15 +27,27 @@ function report(reportTest){ }); } -MockLocation = function() { +function MockBrowser() { this.url = "http://server"; + this.watches = []; +} +MockBrowser.prototype = { + getUrl: function(){ + return this.url; + }, + + setUrl: function(url){ + this.url = url; + }, + + watchUrl: function(fn) { + this.watches.push(fn); + } }; -MockLocation.prototype.get = function(){ - return this.url; -}; -MockLocation.prototype.set = function(url){ - this.url = url; -}; + +angularService('$browser', function(){ + return new MockBrowser(); +}); function childNode(element, index) { return jqLite(element[0].childNodes[index]); @@ -80,7 +92,7 @@ function sortedHtml(element) { } })(element[0]); return html; -}; +} function isVisible(node) { var display = node.css('display'); |
