[test] Refactor tests to be generalized.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-app-hello-world/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-app-hello-world/commit/6c162b39 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-app-hello-world/tree/6c162b39 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-app-hello-world/diff/6c162b39 Branch: refs/heads/master Commit: 6c162b39ef05dbdb348a9e766af7564e73d826cf Parents: b18d442 Author: Michael Brooks <mich...@michaelbrooks.ca> Authored: Fri Jul 13 16:40:19 2012 -0700 Committer: Michael Brooks <mich...@michaelbrooks.ca> Committed: Fri Jul 13 16:40:19 2012 -0700 ---------------------------------------------------------------------- www/js/index.js | 8 ++--- www/spec/index.js | 66 +++++++++++------------------------------------ 2 files changed, 19 insertions(+), 55 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-app-hello-world/blob/6c162b39/www/js/index.js ---------------------------------------------------------------------- diff --git a/www/js/index.js b/www/js/index.js index ce8d9b2..aa84f8c 100644 --- a/www/js/index.js +++ b/www/js/index.js @@ -3,12 +3,10 @@ var app = { this.bind(); }, bind: function() { - document.addEventListener('deviceready', this.event.deviceready, false); + document.addEventListener('deviceready', this.deviceready, false); }, - event: { - deviceready: function() { - app.report('deviceready'); - } + deviceready: function() { + app.report('deviceready'); }, report: function(id) { document.getElementById(id).innerHTML= 'ok'; http://git-wip-us.apache.org/repos/asf/incubator-cordova-app-hello-world/blob/6c162b39/www/spec/index.js ---------------------------------------------------------------------- diff --git a/www/spec/index.js b/www/spec/index.js index 930fe85..74d9062 100644 --- a/www/spec/index.js +++ b/www/spec/index.js @@ -1,65 +1,31 @@ describe('app', function() { - it('should exist', function() { - expect(app).toBeDefined(); - }); - describe('initialize', function() { - it('should exist', function() { - expect(app.initialize).toBeDefined(); - }); - - it('should bind events', function() { - spyOn(app, 'bind'); - app.initialize(); - expect(app.bind).toHaveBeenCalled(); - }); - }); + it('should bind deviceready', function() { + runs(function() { + spyOn(app, 'deviceready'); + app.initialize(); + helper.trigger(window.document, 'deviceready'); + }); - describe('bind', function() { - it('should exist', function() { - expect(app.bind).toBeDefined(); - }); + waitsFor(function() { + return (app.deviceready.calls.length > 0); + }, 'deviceready should be called once', 500); - describe('deviceready', function() { - it('should call app.event.deviceready on deviceready', function() { - runs(function() { - spyOn(app.event, 'deviceready'); - app.bind(); - helper.trigger(window.document, 'deviceready'); - }); - waitsFor(function() { - return (app.event.deviceready.calls.length > 0); - }, 'deviceready should be called once', 500); - runs(function() { - expect(app.event.deviceready).toHaveBeenCalled(); - }); + runs(function() { + expect(app.deviceready).toHaveBeenCalled(); }); }); }); - describe('event', function() { - it('should exist', function() { - expect(app.event).toBeDefined(); - }); - - describe('deviceready', function() { - it('should exist', function() { - expect(app.event.deviceready).toBeDefined(); - }); - - it('should report that it fired', function() { - spyOn(app, 'report'); - app.event.deviceready(); - expect(app.report).toHaveBeenCalledWith('deviceready'); - }); + describe('deviceready', function() { + it('should report that it fired', function() { + spyOn(app, 'report'); + app.deviceready(); + expect(app.report).toHaveBeenCalledWith('deviceready'); }); }); describe('report', function() { - it('should exist', function() { - expect(app.report).toBeDefined(); - }); - it('should report "ok" for the given ID', function() { document.getElementById('stage').innerHTML = '<span id="deviceready"></span>'; app.report('deviceready');