dwf/rva: async working with .waits() syntax; simple case

This commit is contained in:
pivotal 2008-12-01 14:24:13 -08:00
parent a4979fe851
commit 3e02023d9f
5 changed files with 89 additions and 53 deletions

View File

@ -83,7 +83,7 @@
<state />
</provider>
<provider selected="true" editor-type-id="text-editor">
<state line="19" column="20" selection-start="652" selection-end="652" vertical-scroll-proportion="0.37063655">
<state line="15" column="26" selection-start="541" selection-end="541" vertical-scroll-proportion="0.2926078">
<folding />
</state>
</provider>
@ -92,7 +92,7 @@
<file leaf-file-name="bootstrap.js" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor">
<state line="171" column="38" selection-start="4839" selection-end="4839" vertical-scroll-proportion="0.7267498">
<state line="54" column="17" selection-start="1594" selection-end="1594" vertical-scroll-proportion="0.46705997">
<folding />
</state>
</provider>
@ -101,7 +101,7 @@
<file leaf-file-name="test.css" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/test.css">
<provider selected="true" editor-type-id="text-editor">
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
<state line="5" column="0" selection-start="118" selection-end="118" vertical-scroll-proportion="0.091083415">
<folding />
</state>
</provider>
@ -110,7 +110,7 @@
<file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor">
<state line="80" column="6" selection-start="1900" selection-end="1900" vertical-scroll-proportion="0.27918288">
<state line="100" column="0" selection-start="2241" selection-end="2241" vertical-scroll-proportion="0.53793776">
<folding />
</state>
</provider>
@ -515,9 +515,9 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/test.css">
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor">
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
<state line="100" column="0" selection-start="2241" selection-end="2241" vertical-scroll-proportion="0.53793776">
<folding />
</state>
</provider>
@ -527,21 +527,21 @@
<state />
</provider>
<provider selected="true" editor-type-id="text-editor">
<state line="19" column="20" selection-start="652" selection-end="652" vertical-scroll-proportion="0.37063655">
<state line="15" column="26" selection-start="541" selection-end="541" vertical-scroll-proportion="0.2926078">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<entry file="file://$PROJECT_DIR$/test/test.css">
<provider selected="true" editor-type-id="text-editor">
<state line="80" column="6" selection-start="1900" selection-end="1900" vertical-scroll-proportion="0.27918288">
<state line="5" column="0" selection-start="118" selection-end="118" vertical-scroll-proportion="0.091083415">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor">
<state line="171" column="38" selection-start="4839" selection-end="4839" vertical-scroll-proportion="0.7267498">
<state line="54" column="17" selection-start="1594" selection-end="1594" vertical-scroll-proportion="0.46705997">
<folding />
</state>
</provider>

View File

@ -3,9 +3,10 @@
// Object.create instead of new Object
if (typeof Object.create !== 'function') {
Object.create = function (o) {
var F = function () {};
F.prototype = o;
return new F();
var F = function () {
};
F.prototype = o;
return new F();
};
}
@ -41,13 +42,13 @@ Matchers.method('report', function (result, failing_message) {
Matchers.method('should_equal', function (expected) {
return this.report((this.actual === expected),
'Expected ' + expected + ' but got ' + this.actual + '.');
'Expected ' + expected + ' but got ' + this.actual + '.');
});
Matchers.method('should_not_equal', function (expected) {
return this.report((this.actual !== expected),
'Expected ' + expected + ' to not equal ' + this.actual + ', but it does.');
'Expected ' + expected + ' to not equal ' + this.actual + ', but it does.');
});
/*
@ -72,24 +73,58 @@ var it = function (description, func) {
return that;
}
var queuedFunction = function(func, timeout, spec) {
var that = {
func: func,
next: function () {spec.finish()},
execute: function () {
if (timeout > 0) {
setTimeout(function () {
that.func();
that.next();
}, timeout);
} else {
that.func();
that.next();
}
}
}
return that;
}
var it_async = function (description) {
var that = {
description: description,
queue: [],
currentTimeout: 0,
waits: function (timeout) {
that.currentTimeout = timeout;
return that;
},
resetTimeout: function() {
that.currentTimeout = 0;
},
finish: function() {
that.done = true;
},
done: false,
execute: function () {
for(i = 0; i < that.queue.length; i++) {
that.queue[i]();
if (that.queue[0]) {
that.queue[0].execute();
}
}
};
};
var addToQueue = function(func) {
that.queue.push(func);
currentFunction = queuedFunction(func, that.currentTimeout, that);
that.queue.push(currentFunction);
if (that.previousFunction) {
that.previousFunction.next = function () {
currentFunction.execute();
}
}
that.resetTimeout();
that.previousFunction = currentFunction;
return that;
}

View File

@ -12,7 +12,8 @@
<h1>
Running all Jasmine Test Suites
</h1>
<div id="icons">
<div id="icon_wrapper">
<span id="icons"></span>
<img id="spinner" src="spinner.gif" alt="" />
</div>
<div id="report">

58
test/bootstrap.js vendored
View File

@ -151,46 +151,50 @@ var testAsyncSpecs = function () {
runs(function () {
foo++;
}).then(function() {
expects_that(foo).should_equal(1)
});
a_spec.execute();
reporter.test((Jasmine.results.length === 1),
'Spec queue did not run all functions');
reporter.test((Jasmine.results[0].passed === true),
'Queued expectation failed');
Jasmine = jasmine_init();
foo = 0;
a_spec = it_async('spec w/ queued statments').
runs(function () {
setTimeout(function() {
foo++
}, 500);
}).waits(1000).then(function() {
expects_that(foo).should_equal(1);
});
a_spec.execute();
reporter.test((Jasmine.results.length === 1),
'Spec queue did not run all functions');
'No call to waits(): Spec queue did not run all functions');
reporter.test((Jasmine.results[0].passed === true),
'Queued expectation failed');
'No call to waits(): Queued expectation failed');
Jasmine = jasmine_init();
foo = 0;
a_spec = it_async('spec w/ queued statments').
runs(function () {
setTimeout(function() {
foo++
}, 500);
}).waits(1000).
then(function() {
expects_that(foo).should_equal(1);
});
a_spec.execute();
setTimeout(function(){
reporter.test((Jasmine.results.length === 1),
'Calling waits(): Spec queue did not run all functions');
reporter.test((Jasmine.results[0].passed === true),
'Calling waits(): Queued expectation failed');
}, 1250);
}
var runTests = function () {
$('spinner').show();
// testMatchersComparisons();
// testMatchersReporting();
// testSpecs();
testMatchersComparisons();
testMatchersReporting();
testSpecs();
testAsyncSpecs();
$('spinner').hide();
reporter.summary();
setTimeout(function() {
$('spinner').hide();
reporter.summary();
}, 1500);
}
//it('should be an async test') {

View File

@ -3,10 +3,6 @@ body {
padding-left: 40px;
}
img#spinner {
display: block;
}
h1 {
padding-top: 20px;
font-weight: bold;