dwf/rva: more async refactoring; results now stored on a per-spec basis;
This commit is contained in:
parent
0ccb6dfc90
commit
29a0e1f519
34
jasmine.iws
34
jasmine.iws
@ -92,7 +92,7 @@
|
|||||||
<file leaf-file-name="bootstrap.js" pinned="false" current="true" current-in-tab="true">
|
<file leaf-file-name="bootstrap.js" pinned="false" current="true" current-in-tab="true">
|
||||||
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
|
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state line="238" column="6" selection-start="7001" selection-end="7001" vertical-scroll-proportion="0.6903164">
|
<state line="230" column="37" selection-start="6830" selection-end="6830" vertical-scroll-proportion="0.74496645">
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
@ -110,7 +110,7 @@
|
|||||||
<file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
|
<file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
|
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state line="74" column="0" selection-start="1733" selection-end="1733" vertical-scroll-proportion="0.13132295">
|
<state line="63" column="6" selection-start="1593" selection-end="1593" vertical-scroll-proportion="0.40661478">
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
@ -515,6 +515,20 @@
|
|||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/test/test.css">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<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$/lib/jasmine.js">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state line="63" column="6" selection-start="1593" selection-end="1593" vertical-scroll-proportion="0.40661478">
|
||||||
|
<folding />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/test/bootstrap.html">
|
<entry file="file://$PROJECT_DIR$/test/bootstrap.html">
|
||||||
<provider editor-type-id="HtmlPreview">
|
<provider editor-type-id="HtmlPreview">
|
||||||
<state />
|
<state />
|
||||||
@ -525,23 +539,9 @@
|
|||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/test/test.css">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<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$/lib/jasmine.js">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<state line="74" column="0" selection-start="1733" selection-end="1733" vertical-scroll-proportion="0.13132295">
|
|
||||||
<folding />
|
|
||||||
</state>
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
|
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state line="238" column="6" selection-start="7001" selection-end="7001" vertical-scroll-proportion="0.6903164">
|
<state line="230" column="37" selection-start="6830" selection-end="6830" vertical-scroll-proportion="0.74496645">
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -25,14 +25,15 @@ if (typeof Function.method !== 'function') {
|
|||||||
/*
|
/*
|
||||||
* Matchers methods; add your own with Matchers.method()
|
* Matchers methods; add your own with Matchers.method()
|
||||||
*/
|
*/
|
||||||
Matchers = function (actual) {
|
Matchers = function (actual, results) {
|
||||||
this.actual = actual;
|
this.actual = actual;
|
||||||
this.passing_message = 'Passed.'
|
this.passing_message = 'Passed.'
|
||||||
|
this.results = results || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
Matchers.method('report', function (result, failing_message) {
|
Matchers.method('report', function (result, failing_message) {
|
||||||
|
|
||||||
Jasmine.results.push({
|
this.results.push({
|
||||||
passed: result,
|
passed: result,
|
||||||
message: result ? this.passing_message : failing_message
|
message: result ? this.passing_message : failing_message
|
||||||
});
|
});
|
||||||
@ -51,27 +52,9 @@ Matchers.method('should_not_equal', function (expected) {
|
|||||||
'Expected ' + expected + ' to not equal ' + this.actual + ', but it does.');
|
'Expected ' + expected + ' to not equal ' + this.actual + ', but it does.');
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
* expects_hat helper method that allows for chaining Matcher
|
|
||||||
*/
|
|
||||||
var expects_that = function (actual) {
|
|
||||||
return new Matchers(actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Jasmine spec constructor
|
* Jasmine spec constructor
|
||||||
*/
|
*/
|
||||||
//var it = function (description, func) {
|
|
||||||
// var that = {
|
|
||||||
// description: description,
|
|
||||||
// func: func,
|
|
||||||
// done: false,
|
|
||||||
// execute: function() {
|
|
||||||
// that.func.apply(that);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return that;
|
|
||||||
//}
|
|
||||||
|
|
||||||
var queuedFunction = function(func, timeout, spec) {
|
var queuedFunction = function(func, timeout, spec) {
|
||||||
var that = {
|
var that = {
|
||||||
@ -82,11 +65,11 @@ var queuedFunction = function(func, timeout, spec) {
|
|||||||
execute: function () {
|
execute: function () {
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
that.func();
|
that.func.apply(spec);
|
||||||
that.next();
|
that.next();
|
||||||
}, timeout);
|
}, timeout);
|
||||||
} else {
|
} else {
|
||||||
that.func();
|
that.func.apply(spec);
|
||||||
that.next();
|
that.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,12 +77,18 @@ var queuedFunction = function(func, timeout, spec) {
|
|||||||
return that;
|
return that;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var it = function (description) {
|
var it = function (description) {
|
||||||
var that = {
|
var that = {
|
||||||
description: description,
|
description: description,
|
||||||
queue: [],
|
queue: [],
|
||||||
currentTimeout: 0,
|
currentTimeout: 0,
|
||||||
done: false,
|
done: false,
|
||||||
|
results: [],
|
||||||
|
|
||||||
|
expects_that: function (actual) {
|
||||||
|
return new Matchers(actual, that.results);
|
||||||
|
},
|
||||||
|
|
||||||
waits: function (timeout) {
|
waits: function (timeout) {
|
||||||
that.currentTimeout = timeout;
|
that.currentTimeout = timeout;
|
||||||
|
99
test/bootstrap.js
vendored
99
test/bootstrap.js
vendored
@ -42,126 +42,123 @@ var reporter = function () {
|
|||||||
}();
|
}();
|
||||||
|
|
||||||
var testMatchersComparisons = function () {
|
var testMatchersComparisons = function () {
|
||||||
Jasmine = jasmine_init();
|
var expected = new Matchers(true);
|
||||||
reporter.test(expects_that(true).should_equal(true),
|
reporter.test(expected.should_equal(true),
|
||||||
'expects_that(true).should_equal(true) returned false');
|
'expects_that(true).should_equal(true) returned false');
|
||||||
|
|
||||||
reporter.test(!(expects_that(false).should_equal(true)),
|
expected = new Matchers(false);
|
||||||
|
reporter.test(!(expected.should_equal(true)),
|
||||||
'expects_that(true).should_equal(true) returned true');
|
'expects_that(true).should_equal(true) returned true');
|
||||||
|
|
||||||
reporter.test(expects_that(true).should_not_equal(false),
|
expected = new Matchers(true);
|
||||||
|
reporter.test(expected.should_not_equal(false),
|
||||||
'expects_that(true).should_not_equal(false) retruned false');
|
'expects_that(true).should_not_equal(false) retruned false');
|
||||||
|
|
||||||
reporter.test(!(expects_that(true).should_not_equal(true)),
|
expected = new Matchers(true);
|
||||||
|
reporter.test(!(expected.should_not_equal(true)),
|
||||||
'expects_that(true).should_not_equal(false) retruned true');
|
'expects_that(true).should_not_equal(false) retruned true');
|
||||||
}
|
}
|
||||||
|
|
||||||
var testMatchersReporting = function () {
|
var testMatchersReporting = function () {
|
||||||
Jasmine = jasmine_init();
|
|
||||||
|
|
||||||
expects_that(true).should_equal(true);
|
var results = [];
|
||||||
expects_that(false).should_equal(true);
|
var expected = new Matchers(true, results);
|
||||||
|
expected.should_equal(true);
|
||||||
|
expected.should_equal(false);
|
||||||
|
|
||||||
reporter.test((Jasmine.results.length == 2),
|
reporter.test((results.length == 2),
|
||||||
"Jasmine results array doesn't have 2 results");
|
"Results array doesn't have 2 results");
|
||||||
|
|
||||||
reporter.test((Jasmine.results[0].passed == true),
|
reporter.test((results[0].passed == true),
|
||||||
"First spec didn't pass");
|
"First spec didn't pass");
|
||||||
|
|
||||||
reporter.test((Jasmine.results[1].passed == false),
|
reporter.test((results[1].passed == false),
|
||||||
"Second spec did pass");
|
"Second spec did pass");
|
||||||
|
|
||||||
Jasmine = jasmine_init();
|
results = [];
|
||||||
|
var expected = new Matchers(false, results);
|
||||||
|
expected.should_equal(true);
|
||||||
|
|
||||||
expects_that(false).should_equal(true);
|
reporter.test((results[0].message == 'Expected true but got false.'),
|
||||||
|
|
||||||
reporter.test((Jasmine.results[0].message == 'Expected true but got false.'),
|
|
||||||
"Failed expectation didn't test the failure message");
|
"Failed expectation didn't test the failure message");
|
||||||
|
|
||||||
Jasmine = jasmine_init();
|
results = [];
|
||||||
|
var expected = new Matchers(true, results);
|
||||||
|
expected.should_equal(true);
|
||||||
|
|
||||||
expects_that(true).should_equal(true);
|
reporter.test((results[0].message == 'Passed.'),
|
||||||
|
|
||||||
reporter.test((Jasmine.results[0].message == 'Passed.'),
|
|
||||||
"Passing expectation didn't test the passing message");
|
"Passing expectation didn't test the passing message");
|
||||||
}
|
}
|
||||||
|
|
||||||
var testSpecs = function () {
|
var testSpecs = function () {
|
||||||
Jasmine = jasmine_init();
|
|
||||||
var spec = it('new spec');
|
var spec = it('new spec');
|
||||||
reporter.test((spec.description == 'new spec'),
|
reporter.test((spec.description == 'new spec'),
|
||||||
"Spec did not have a description");
|
"Spec did not have a description");
|
||||||
|
|
||||||
Jasmine = jasmine_init();
|
|
||||||
var another_spec = it('spec with an expectation').runs(function () {
|
var another_spec = it('spec with an expectation').runs(function () {
|
||||||
var foo = 'bar';
|
var foo = 'bar';
|
||||||
expects_that(foo).should_equal('bar');
|
this.expects_that(foo).should_equal('bar');
|
||||||
});
|
});
|
||||||
another_spec.execute();
|
another_spec.execute();
|
||||||
another_spec.done = true;
|
another_spec.done = true;
|
||||||
|
|
||||||
reporter.test((Jasmine.results.length == 1),
|
reporter.test((another_spec.results.length == 1),
|
||||||
"Results aren't there after a spec was executed");
|
"Results aren't there after a spec was executed");
|
||||||
reporter.test((Jasmine.results[0].passed == true),
|
reporter.test((another_spec.results[0].passed == true),
|
||||||
"Results has a result, but it's true");
|
"Results has a result, but it's true");
|
||||||
|
|
||||||
Jasmine = jasmine_init();
|
|
||||||
var yet_another_spec = it('spec with failing expectation').runs(function () {
|
var yet_another_spec = it('spec with failing expectation').runs(function () {
|
||||||
var foo = 'bar';
|
var foo = 'bar';
|
||||||
expects_that(foo).should_equal('baz');
|
this.expects_that(foo).should_equal('baz');
|
||||||
});
|
});
|
||||||
yet_another_spec.execute();
|
yet_another_spec.execute();
|
||||||
another_spec.done = true;
|
yet_another_spec.done = true;
|
||||||
|
|
||||||
reporter.test((Jasmine.results[0].passed == false),
|
reporter.test((yet_another_spec.results[0].passed == false),
|
||||||
"Expectation that failed, passed");
|
"Expectation that failed, passed");
|
||||||
|
|
||||||
Jasmine = jasmine_init();
|
|
||||||
var yet_yet_another_spec = it('spec with multiple assertions').runs( function () {
|
var yet_yet_another_spec = it('spec with multiple assertions').runs( function () {
|
||||||
var foo = 'bar';
|
var foo = 'bar';
|
||||||
var baz = 'quux';
|
var baz = 'quux';
|
||||||
|
|
||||||
expects_that(foo).should_equal('bar');
|
this.expects_that(foo).should_equal('bar');
|
||||||
expects_that(baz).should_equal('quux');
|
this.expects_that(baz).should_equal('quux');
|
||||||
});
|
});
|
||||||
yet_yet_another_spec.execute();
|
yet_yet_another_spec.execute();
|
||||||
another_spec.done = true;
|
yet_yet_another_spec.done = true;
|
||||||
|
|
||||||
reporter.test((Jasmine.results.length == 2),
|
reporter.test((yet_yet_another_spec.results.length == 2),
|
||||||
"Spec doesn't support multiple expectations");
|
"Spec doesn't support multiple expectations");
|
||||||
}
|
}
|
||||||
|
|
||||||
var testAsyncSpecs = function () {
|
var testAsyncSpecs = function () {
|
||||||
Jasmine = jasmine_init();
|
|
||||||
var foo = 0;
|
var foo = 0;
|
||||||
|
|
||||||
var a_spec = it('simple queue test').
|
var a_spec = it('simple queue test').
|
||||||
runs(function () {
|
runs(function () {
|
||||||
foo++;
|
foo++;
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
expects_that(foo).should_equal(1)
|
this.expects_that(foo).should_equal(1)
|
||||||
});
|
});
|
||||||
|
|
||||||
reporter.test(a_spec.queue.length === 2,
|
reporter.test(a_spec.queue.length === 2,
|
||||||
'Spec queue length is not 2');
|
'Spec queue length is not 2');
|
||||||
|
|
||||||
Jasmine = jasmine_init();
|
|
||||||
foo = 0;
|
foo = 0;
|
||||||
a_spec = it('spec w/ queued statments').
|
a_spec = it('spec w/ queued statments').
|
||||||
runs(function () {
|
runs(function () {
|
||||||
foo++;
|
foo++;
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
expects_that(foo).should_equal(1);
|
this.expects_that(foo).should_equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
a_spec.execute();
|
a_spec.execute();
|
||||||
|
|
||||||
reporter.test((Jasmine.results.length === 1),
|
reporter.test((a_spec.results.length === 1),
|
||||||
'No call to waits(): 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),
|
reporter.test((a_spec.results[0].passed === true),
|
||||||
'No call to waits(): Queued expectation failed');
|
'No call to waits(): Queued expectation failed');
|
||||||
|
|
||||||
Jasmine = jasmine_init();
|
|
||||||
foo = 0;
|
foo = 0;
|
||||||
a_spec = it('spec w/ queued statments').
|
a_spec = it('spec w/ queued statments').
|
||||||
runs(function () {
|
runs(function () {
|
||||||
@ -170,20 +167,19 @@ var testAsyncSpecs = function () {
|
|||||||
}, 500);
|
}, 500);
|
||||||
}).waits(1000).
|
}).waits(1000).
|
||||||
then(function() {
|
then(function() {
|
||||||
expects_that(foo).should_equal(1);
|
this.expects_that(foo).should_equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
a_spec.execute();
|
a_spec.execute();
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
reporter.test((Jasmine.results.length === 1),
|
reporter.test((a_spec.results.length === 1),
|
||||||
'Calling waits(): Spec queue did not run all functions');
|
'Calling waits(): Spec queue did not run all functions');
|
||||||
|
|
||||||
reporter.test((Jasmine.results[0].passed === true),
|
reporter.test((a_spec.results[0].passed === true),
|
||||||
'Calling waits(): Queued expectation failed');
|
'Calling waits(): Queued expectation failed');
|
||||||
}, 1250);
|
}, 1250);
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
Jasmine = jasmine_init();
|
|
||||||
var bar = 0;
|
var bar = 0;
|
||||||
var another_spec = it('spec w/ queued statments').
|
var another_spec = it('spec w/ queued statments').
|
||||||
runs(function () {
|
runs(function () {
|
||||||
@ -199,22 +195,21 @@ var testAsyncSpecs = function () {
|
|||||||
}).
|
}).
|
||||||
waits(1500).
|
waits(1500).
|
||||||
then(function() {
|
then(function() {
|
||||||
expects_that(bar).should_equal(2);
|
this.expects_that(bar).should_equal(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
another_spec.execute();
|
another_spec.execute();
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
reporter.test((another_spec.queue.length === 3),
|
reporter.test((another_spec.queue.length === 3),
|
||||||
'Calling 2 waits(): Spec queue was less than expected length');
|
'Calling 2 waits(): Spec queue was less than expected length');
|
||||||
reporter.test((Jasmine.results.length === 1),
|
reporter.test((another_spec.results.length === 1),
|
||||||
'Calling 2 waits(): Spec queue did not run all functions');
|
'Calling 2 waits(): Spec queue did not run all functions');
|
||||||
reporter.test((Jasmine.results[0].passed === true),
|
reporter.test((another_spec.results[0].passed === true),
|
||||||
'Calling 2 waits(): Queued expectation failed');
|
'Calling 2 waits(): Queued expectation failed');
|
||||||
}, 2500);
|
}, 2500);
|
||||||
}, 1500);
|
}, 1500);
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
Jasmine = jasmine_init();
|
|
||||||
var baz = 0;
|
var baz = 0;
|
||||||
var yet_another_spec = it('spec w/ async fail').
|
var yet_another_spec = it('spec w/ async fail').
|
||||||
runs(function () {
|
runs(function () {
|
||||||
@ -224,16 +219,16 @@ var testAsyncSpecs = function () {
|
|||||||
}).
|
}).
|
||||||
waits(100).
|
waits(100).
|
||||||
then(function() {
|
then(function() {
|
||||||
expects_that(baz).should_equal(1);
|
this.expects_that(baz).should_equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
yet_another_spec.execute();
|
yet_another_spec.execute();
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
reporter.test((yet_another_spec.queue.length === 2),
|
reporter.test((yet_another_spec.queue.length === 2),
|
||||||
'Calling 2 waits(): Spec queue was less than expected length');
|
'Calling 2 waits(): Spec queue was less than expected length');
|
||||||
reporter.test((Jasmine.results.length === 1),
|
reporter.test((yet_another_spec.results.length === 1),
|
||||||
'Calling 2 waits(): Spec queue did not run all functions');
|
'Calling 2 waits(): Spec queue did not run all functions');
|
||||||
reporter.test((Jasmine.results[0].passed === false),
|
reporter.test((yet_another_spec.results[0].passed === false),
|
||||||
'Calling 2 waits(): Queued expectation failed');
|
'Calling 2 waits(): Queued expectation failed');
|
||||||
}, 2500);
|
}, 2500);
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
Loading…
Reference in New Issue
Block a user