Fix test which was causing the Chrome runner to fail. Upgraded JSTD to latest. Cleanup whitespace.

This commit is contained in:
Misko Hevery 2010-10-23 13:10:42 -07:00
parent 8a867cee22
commit 6ddcf91861
9 changed files with 52 additions and 50 deletions

Binary file not shown.

View file

@ -9,8 +9,8 @@ describe('angular.scenario.Application', function() {
it('should return new $window and $document after navigate', function() { it('should return new $window and $document after navigate', function() {
var testWindow, testDocument, counter = 0; var testWindow, testDocument, counter = 0;
app.navigateTo = noop; app.navigateTo = noop;
app.getWindow = function() { app.getWindow = function() {
return {x:counter++, document:{x:counter++}}; return {x:counter++, document:{x:counter++}};
}; };
app.navigateTo('http://www.google.com/'); app.navigateTo('http://www.google.com/');
app.executeAction(function($document, $window) { app.executeAction(function($document, $window) {
@ -26,8 +26,8 @@ describe('angular.scenario.Application', function() {
it('should execute callback with correct arguments', function() { it('should execute callback with correct arguments', function() {
var testWindow = {document: {}}; var testWindow = {document: {}};
app.getWindow = function() { app.getWindow = function() {
return testWindow; return testWindow;
}; };
app.executeAction(function($window, $document) { app.executeAction(function($window, $document) {
expect(this).toEqual(app); expect(this).toEqual(app);
@ -35,7 +35,7 @@ describe('angular.scenario.Application', function() {
expect($window).toEqual(testWindow); expect($window).toEqual(testWindow);
}); });
}); });
it('should create a new iframe each time', function() { it('should create a new iframe each time', function() {
app.navigateTo('about:blank'); app.navigateTo('about:blank');
var frame = app.getFrame(); var frame = app.getFrame();
@ -43,27 +43,27 @@ describe('angular.scenario.Application', function() {
app.navigateTo('about:blank'); app.navigateTo('about:blank');
expect(app.getFrame().attr('test')).toBeFalsy(); expect(app.getFrame().attr('test')).toBeFalsy();
}); });
it('should URL description bar', function() { it('should URL description bar', function() {
app.navigateTo('about:blank'); app.navigateTo('about:blank');
var anchor = frames.find('> h2 a'); var anchor = frames.find('> h2 a');
expect(anchor.attr('href')).toEqual('about:blank'); expect(anchor.attr('href')).toEqual('about:blank');
expect(anchor.text()).toEqual('about:blank'); expect(anchor.text()).toEqual('about:blank');
}); });
it('should call onload handler when frame loads', function() { it('should call onload handler when frame loads', function() {
var called; var called;
app.getFrame = function() { app.getFrame = function() {
// Mock a little jQuery // Mock a little jQuery
var result = { var result = {
remove: function() { remove: function() {
return result; return result;
}, },
attr: function(key, value) { attr: function(key, value) {
return (!value) ? 'attribute value' : result; return (!value) ? 'attribute value' : result;
}, },
load: function() { load: function() {
called = true; called = true;
} }
}; };
return result; return result;

View file

@ -4,21 +4,21 @@ describe('angular.scenario.Describe', function() {
beforeEach(function() { beforeEach(function() {
root = new angular.scenario.Describe(); root = new angular.scenario.Describe();
/** /**
* Simple callback logging system. Use to assert proper order of calls. * Simple callback logging system. Use to assert proper order of calls.
*/ */
log = function(text) { log = function(text) {
log.text = log.text + text; log.text = log.text + text;
}; };
log.fn = function(text) { log.fn = function(text) {
return function(done){ return function(done){
log(text); log(text);
(done || angular.noop)(); (done || angular.noop)();
}; };
}; };
log.reset = function() { log.reset = function() {
log.text = ''; log.text = '';
}; };
log.reset(); log.reset();
}); });
@ -50,7 +50,7 @@ describe('angular.scenario.Describe', function() {
specs[1].after(); specs[1].after();
expect(log.text).toEqual('{1}'); expect(log.text).toEqual('{1}');
}); });
it('should link nested describe blocks with parent and children', function() { it('should link nested describe blocks with parent and children', function() {
root.describe('A', function() { root.describe('A', function() {
this.it('1', angular.noop); this.it('1', angular.noop);
@ -65,7 +65,7 @@ describe('angular.scenario.Describe', function() {
expect(specs[2].definition.parent).toEqual(root); expect(specs[2].definition.parent).toEqual(root);
expect(specs[0].definition.parent).toEqual(specs[2].definition.children[0]); expect(specs[0].definition.parent).toEqual(specs[2].definition.children[0]);
}); });
it('should not process xit and xdescribe', function() { it('should not process xit and xdescribe', function() {
root.describe('A', function() { root.describe('A', function() {
this.xit('1', angular.noop); this.xit('1', angular.noop);
@ -79,7 +79,7 @@ describe('angular.scenario.Describe', function() {
var specs = root.getSpecs(); var specs = root.getSpecs();
expect(specs.length).toEqual(0); expect(specs.length).toEqual(0);
}); });
it('should create uniqueIds in the tree', function() { it('should create uniqueIds in the tree', function() {
angular.scenario.Describe.id = 0; angular.scenario.Describe.id = 0;
var a = new angular.scenario.Describe(); var a = new angular.scenario.Describe();

View file

@ -1,6 +1,6 @@
describe('angular.scenario.Future', function() { describe('angular.scenario.Future', function() {
var future; var future;
it('should set the sane defaults', function() { it('should set the sane defaults', function() {
var behavior = function() {}; var behavior = function() {};
var future = new angular.scenario.Future('test name', behavior, 'foo'); var future = new angular.scenario.Future('test name', behavior, 'foo');
@ -11,7 +11,7 @@ describe('angular.scenario.Future', function() {
expect(future.fulfilled).toBeFalsy(); expect(future.fulfilled).toBeFalsy();
expect(future.parser).toEqual(angular.identity); expect(future.parser).toEqual(angular.identity);
}); });
it('should be fulfilled after execution and done callback', function() { it('should be fulfilled after execution and done callback', function() {
var future = new angular.scenario.Future('test name', function(done) { var future = new angular.scenario.Future('test name', function(done) {
done(); done();
@ -19,7 +19,7 @@ describe('angular.scenario.Future', function() {
future.execute(angular.noop); future.execute(angular.noop);
expect(future.fulfilled).toBeTruthy(); expect(future.fulfilled).toBeTruthy();
}); });
it('should take callback with (error, result) and forward', function() { it('should take callback with (error, result) and forward', function() {
var future = new angular.scenario.Future('test name', function(done) { var future = new angular.scenario.Future('test name', function(done) {
done(10, 20); done(10, 20);
@ -29,7 +29,7 @@ describe('angular.scenario.Future', function() {
expect(result).toEqual(20); expect(result).toEqual(20);
}); });
}); });
it('should use error as value if provided', function() { it('should use error as value if provided', function() {
var future = new angular.scenario.Future('test name', function(done) { var future = new angular.scenario.Future('test name', function(done) {
done(10, 20); done(10, 20);
@ -37,7 +37,7 @@ describe('angular.scenario.Future', function() {
future.execute(angular.noop); future.execute(angular.noop);
expect(future.value).toEqual(10); expect(future.value).toEqual(10);
}); });
it('should parse json with fromJson', function() { it('should parse json with fromJson', function() {
var future = new angular.scenario.Future('test name', function(done) { var future = new angular.scenario.Future('test name', function(done) {
done(null, "{test: 'foo'}"); done(null, "{test: 'foo'}");
@ -45,7 +45,7 @@ describe('angular.scenario.Future', function() {
future.fromJson().execute(angular.noop); future.fromJson().execute(angular.noop);
expect(future.value).toEqual({test: 'foo'}); expect(future.value).toEqual({test: 'foo'});
}); });
it('should convert to json with toJson', function() { it('should convert to json with toJson', function() {
var future = new angular.scenario.Future('test name', function(done) { var future = new angular.scenario.Future('test name', function(done) {
done(null, {test: 'foo'}); done(null, {test: 'foo'});
@ -53,7 +53,7 @@ describe('angular.scenario.Future', function() {
future.toJson().execute(angular.noop); future.toJson().execute(angular.noop);
expect(future.value).toEqual('{"test":"foo"}'); expect(future.value).toEqual('{"test":"foo"}');
}); });
it('should convert with custom parser', function() { it('should convert with custom parser', function() {
var future = new angular.scenario.Future('test name', function(done) { var future = new angular.scenario.Future('test name', function(done) {
done(null, 'foo'); done(null, 'foo');
@ -63,7 +63,7 @@ describe('angular.scenario.Future', function() {
}).execute(angular.noop); }).execute(angular.noop);
expect(future.value).toEqual('FOO'); expect(future.value).toEqual('FOO');
}); });
it('should pass error if parser fails', function() { it('should pass error if parser fails', function() {
var future = new angular.scenario.Future('test name', function(done) { var future = new angular.scenario.Future('test name', function(done) {
done(null, '{'); done(null, '{');
@ -71,5 +71,5 @@ describe('angular.scenario.Future', function() {
future.fromJson().execute(function(error, result) { future.fromJson().execute(function(error, result) {
expect(error).toBeDefined(); expect(error).toBeDefined();
}); });
}); });
}); });

View file

@ -2,7 +2,7 @@ describe('angular.scenario.HtmlUI', function() {
var ui; var ui;
var context; var context;
var spec; var spec;
function line() { return 'unknown:-1'; } function line() { return 'unknown:-1'; }
beforeEach(function() { beforeEach(function() {
@ -85,7 +85,7 @@ describe('angular.scenario.HtmlUI', function() {
expect(timer.innerHTML).toMatch(/ms$/); expect(timer.innerHTML).toMatch(/ms$/);
}); });
}); });
it('should include line if provided', function() { it('should include line if provided', function() {
specUI = ui.addSpec(spec); specUI = ui.addSpec(spec);
specUI.addStep('some step', line).finish('error!'); specUI.addStep('some step', line).finish('error!');

View file

@ -16,7 +16,7 @@ MockSpecRunner.prototype.addFuture = function(name, fn, line) {
describe('angular.scenario.Runner', function() { describe('angular.scenario.Runner', function() {
var $window; var $window;
var runner; var runner;
beforeEach(function() { beforeEach(function() {
// Trick to get the scope out of a DSL statement // Trick to get the scope out of a DSL statement
angular.scenario.dsl('dslAddFuture', function() { angular.scenario.dsl('dslAddFuture', function() {
@ -42,12 +42,12 @@ describe('angular.scenario.Runner', function() {
}; };
runner = new angular.scenario.Runner($window); runner = new angular.scenario.Runner($window);
}); });
afterEach(function() { afterEach(function() {
delete angular.scenario.dsl.dslScope; delete angular.scenario.dsl.dslScope;
delete angular.scenario.dsl.dslChain; delete angular.scenario.dsl.dslChain;
}); });
it('should publish the functions in the public API', function() { it('should publish the functions in the public API', function() {
angular.foreach(runner.api, function(fn, name) { angular.foreach(runner.api, function(fn, name) {
var func; var func;
@ -57,7 +57,7 @@ describe('angular.scenario.Runner', function() {
expect(angular.isFunction(func)).toBeTruthy(); expect(angular.isFunction(func)).toBeTruthy();
}); });
}); });
it('should construct valid describe trees with public API', function() { it('should construct valid describe trees with public API', function() {
var before = []; var before = [];
var after = []; var after = [];
@ -85,7 +85,7 @@ describe('angular.scenario.Runner', function() {
expect(specs[2].definition.parent).toEqual(runner.rootDescribe); expect(specs[2].definition.parent).toEqual(runner.rootDescribe);
expect(specs[0].definition.parent).toEqual(specs[2].definition.children[0]); expect(specs[0].definition.parent).toEqual(specs[2].definition.children[0]);
}); });
it('should publish the DSL statements to the $window', function() { it('should publish the DSL statements to the $window', function() {
$window.describe('describe', function() { $window.describe('describe', function() {
$window.it('1', function() { $window.it('1', function() {
@ -94,7 +94,7 @@ describe('angular.scenario.Runner', function() {
}); });
runner.run(null/*ui*/, null/*application*/, MockSpecRunner, rethrow); runner.run(null/*ui*/, null/*application*/, MockSpecRunner, rethrow);
}); });
it('should create a new scope for each DSL chain', function() { it('should create a new scope for each DSL chain', function() {
$window.describe('describe', function() { $window.describe('describe', function() {
$window.it('1', function() { $window.it('1', function() {

View file

@ -49,7 +49,7 @@ ApplicationMock.prototype = {
describe('angular.scenario.SpecRunner', function() { describe('angular.scenario.SpecRunner', function() {
var $window; var $window;
var runner; var runner;
function createSpec(name, body) { function createSpec(name, body) {
return { return {
name: name, name: name,
@ -93,8 +93,8 @@ describe('angular.scenario.SpecRunner', function() {
it('should execute spec function and notify UI', function() { it('should execute spec function and notify UI', function() {
var finished; var finished;
var ui = new UIMock(); var ui = new UIMock();
var spec = createSpec('test spec', function() { var spec = createSpec('test spec', function() {
this.test = 'some value'; this.test = 'some value';
}); });
runner.addFuture('test future', function(done) { runner.addFuture('test future', function(done) {
done(); done();
@ -115,7 +115,7 @@ describe('angular.scenario.SpecRunner', function() {
it('should execute notify UI on spec setup error', function() { it('should execute notify UI on spec setup error', function() {
var finished; var finished;
var ui = new UIMock(); var ui = new UIMock();
var spec = createSpec('test spec', function() { var spec = createSpec('test spec', function() {
throw 'message'; throw 'message';
}); });
runner.run(ui, spec, function() { runner.run(ui, spec, function() {
@ -166,7 +166,7 @@ describe('angular.scenario.SpecRunner', function() {
'spec finish:' 'spec finish:'
]); ]);
}); });
it('should run after handlers even if error in body of spec', function() { it('should run after handlers even if error in body of spec', function() {
var finished, after; var finished, after;
var ui = new UIMock(); var ui = new UIMock();

View file

@ -190,7 +190,9 @@ describe("angular.scenario.dsl", function() {
describe('Element', function() { describe('Element', function() {
it('should execute click', function() { it('should execute click', function() {
var clicked; var clicked;
doc.append('<a href=""></a>'); // Hash is important, otherwise we actually
// go to a different page and break the runner
doc.append('<a href="#"></a>');
doc.find('a').click(function() { doc.find('a').click(function() {
clicked = true; clicked = true;
}); });

View file

@ -1,6 +1,6 @@
describe('angular.scenario.matchers', function () { describe('angular.scenario.matchers', function () {
var matchers; var matchers;
function expectMatcher(value, test) { function expectMatcher(value, test) {
delete matchers.error; delete matchers.error;
delete matchers.future.value; delete matchers.future.value;
@ -10,9 +10,9 @@ describe('angular.scenario.matchers', function () {
test(); test();
expect(matchers.error).toBeUndefined(); expect(matchers.error).toBeUndefined();
} }
beforeEach(function() { beforeEach(function() {
/** /**
* Mock up the future system wrapped around matchers. * Mock up the future system wrapped around matchers.
* *
* @see Scenario.js#angular.scenario.matcher * @see Scenario.js#angular.scenario.matcher
@ -27,7 +27,7 @@ describe('angular.scenario.matchers', function () {
}; };
angular.extend(matchers, angular.scenario.matcher); angular.extend(matchers, angular.scenario.matcher);
}); });
it('should handle basic matching', function() { it('should handle basic matching', function() {
expectMatcher(10, function() { matchers.toEqual(10); }); expectMatcher(10, function() { matchers.toEqual(10); });
expectMatcher('value', function() { matchers.toBeDefined(); }); expectMatcher('value', function() { matchers.toBeDefined(); });