diff options
| author | Misko Hevery | 2011-11-08 17:40:52 -0800 |
|---|---|---|
| committer | Misko Hevery | 2011-11-14 20:31:15 -0800 |
| commit | 9c0639437607a4fcea379bbaf610600d05d8a9b7 (patch) | |
| tree | 1ae90d93d0139f7791487fe814360904254d39cb /test/scenario | |
| parent | 085e3c611fd0cd48757702c50c67b551a00a0d38 (diff) | |
| download | angular.js-9c0639437607a4fcea379bbaf610600d05d8a9b7.tar.bz2 | |
chore(scenario tests): make scenario tests pass again
Diffstat (limited to 'test/scenario')
| -rw-r--r-- | test/scenario/ApplicationSpec.js | 17 | ||||
| -rw-r--r-- | test/scenario/dslSpec.js | 20 | ||||
| -rw-r--r-- | test/scenario/mocks.js | 16 |
3 files changed, 23 insertions, 30 deletions
diff --git a/test/scenario/ApplicationSpec.js b/test/scenario/ApplicationSpec.js index 8caf1651..86023438 100644 --- a/test/scenario/ApplicationSpec.js +++ b/test/scenario/ApplicationSpec.js @@ -112,22 +112,20 @@ describe('angular.scenario.Application', function() { expect(called).toBeTruthy(); }); - it('should wait for pending requests in executeAction', function() { + it('should wait for pending requests in executeAction', inject(function($injector, $browser) { var called, polled; var handlers = []; var testWindow = { - document: _jQuery('<div class="test-foo"></div>'), + document: jqLite('<div class="test-foo"></div>'), angular: { + element: jqLite, service: {} } }; - testWindow.angular.service.$browser = function() { - return { - notifyWhenNoOutstandingRequests: function(fn) { - handlers.push(fn); - } - }; + $browser.notifyWhenNoOutstandingRequests = function(fn) { + handlers.push(fn); }; + testWindow.document.data('$injector', $injector); app.getWindow_ = function() { return testWindow; }; @@ -138,5 +136,6 @@ describe('angular.scenario.Application', function() { }); expect(handlers.length).toEqual(1); handlers[0](); - }); + dealoc(testWindow.document); + })); }); diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js index 411320e8..29956801 100644 --- a/test/scenario/dslSpec.js +++ b/test/scenario/dslSpec.js @@ -4,13 +4,14 @@ describe("angular.scenario.dsl", function() { var $window, $root; var application, eventLog; - beforeEach(function() { + beforeEach(inject(function($injector) { eventLog = []; $window = { - document: _jQuery("<div></div>"), + document: jqLite('<div class="document"></div>'), angular: new angular.scenario.testing.MockAngular() }; - $root = angular.injector('NG')('$rootScope'); + $window.document.data('$injector', $injector); + $root = $injector('$rootScope'); $root.emit = function(eventName) { eventLog.push(eventName); }; @@ -45,6 +46,10 @@ describe("angular.scenario.dsl", function() { // Just use the real one since it delegates to this.addFuture $root.addFutureAction = angular.scenario. SpecRunner.prototype.addFutureAction; + })); + + afterEach(function(){ + jqLite($window.document).removeData('$injector'); }); describe('Pause', function() { @@ -201,11 +206,14 @@ describe("angular.scenario.dsl", function() { // ex. jQuery('#foo').find('[name="bar"]') // fails // ex. jQuery('#foo [name="bar"]') // works, wtf? // - beforeEach(function() { + beforeEach(inject(function($injector) { doc = _jQuery('<div id="angular-scenario-binding"></div>'); _jQuery(document.body).html('').append(doc); - $window.document = window.document; - }); + + dealoc($window.document); // we are about to override it + $window.document = window.document; + jqLite($window.document).data('$injector', $injector); + })); afterEach(function() { _jQuery(document.body). diff --git a/test/scenario/mocks.js b/test/scenario/mocks.js index 2db8577a..e135390f 100644 --- a/test/scenario/mocks.js +++ b/test/scenario/mocks.js @@ -4,32 +4,18 @@ angular.scenario.testing = angular.scenario.testing || {}; angular.scenario.testing.MockAngular = function() { this.reset(); - this.service = this; + this.element = jqLite; }; angular.scenario.testing.MockAngular.prototype.reset = function() { this.log = []; }; -angular.scenario.testing.MockAngular.prototype.element = function(e) { - return jqLite(e); -}; - -angular.scenario.testing.MockAngular.prototype.$browser = function() { - this.log.push('$brower()'); - return this; -}; - angular.scenario.testing.MockAngular.prototype.poll = function() { this.log.push('$brower.poll()'); return this; }; -angular.scenario.testing.MockAngular.prototype.notifyWhenNoOutstandingRequests = function(fn) { - this.log.push('$brower.notifyWhenNoOutstandingRequests()'); - fn(); -}; - angular.scenario.testing.MockRunner = function() { this.listeners = []; }; |
