2008-11-30 02:12:55 +00:00
|
|
|
// Bootstrap Test Reporter function
|
|
|
|
var reporter = function () {
|
|
|
|
|
|
|
|
var total = 0;
|
|
|
|
var passes = 0;
|
|
|
|
var fails = 0;
|
|
|
|
|
|
|
|
var that = {
|
|
|
|
test: function (result, message) {
|
|
|
|
total++;
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
passes++;
|
|
|
|
iconElement = $('icons');
|
2008-12-10 18:32:23 +00:00
|
|
|
iconElement.appendChild(new Element('img', {src: '../images/go-16.png'}));
|
2008-11-30 02:12:55 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fails++;
|
2008-12-01 20:26:12 +00:00
|
|
|
var fails_report = $('fails');
|
|
|
|
fails_report.show();
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-08 19:35:10 +00:00
|
|
|
var iconElement = $('icons');
|
2008-12-10 18:32:23 +00:00
|
|
|
iconElement.appendChild(new Element('img', {src: '../images/fail-16.png'}));
|
2008-11-30 02:12:55 +00:00
|
|
|
|
|
|
|
var failMessages = $('fail_messages');
|
2008-12-01 20:26:12 +00:00
|
|
|
var newFail = new Element('p', {'class': 'fail'});
|
2008-11-30 02:12:55 +00:00
|
|
|
newFail.innerHTML = message;
|
|
|
|
failMessages.appendChild(newFail);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
summary: function () {
|
2008-12-08 19:35:10 +00:00
|
|
|
var el = new Element('p', {'class': ((fails > 0) ? 'fail_in_summary' : '') });
|
|
|
|
el.innerHTML = total + ' expectations, ' + passes + ' passing, ' + fails + ' failed.';
|
2008-12-01 20:26:12 +00:00
|
|
|
|
|
|
|
var summaryElement = $('results_summary');
|
2008-12-08 19:35:10 +00:00
|
|
|
summaryElement.appendChild(el);
|
2008-12-01 20:26:12 +00:00
|
|
|
summaryElement.show();
|
2008-11-30 02:12:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return that;
|
|
|
|
}();
|
|
|
|
|
|
|
|
var testMatchersComparisons = function () {
|
2008-12-08 21:01:06 +00:00
|
|
|
var expected = new Jasmine.Matchers(true);
|
2008-12-01 23:59:41 +00:00
|
|
|
reporter.test(expected.should_equal(true),
|
2008-12-01 20:26:12 +00:00
|
|
|
'expects_that(true).should_equal(true) returned false');
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-08 21:01:06 +00:00
|
|
|
expected = new Jasmine.Matchers(false);
|
2008-12-01 23:59:41 +00:00
|
|
|
reporter.test(!(expected.should_equal(true)),
|
2008-12-01 20:26:12 +00:00
|
|
|
'expects_that(true).should_equal(true) returned true');
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-08 21:01:06 +00:00
|
|
|
expected = new Jasmine.Matchers(true);
|
2008-12-01 23:59:41 +00:00
|
|
|
reporter.test(expected.should_not_equal(false),
|
2008-12-01 20:26:12 +00:00
|
|
|
'expects_that(true).should_not_equal(false) retruned false');
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-08 21:01:06 +00:00
|
|
|
expected = new Jasmine.Matchers(true);
|
2008-12-01 23:59:41 +00:00
|
|
|
reporter.test(!(expected.should_not_equal(true)),
|
2008-12-01 20:26:12 +00:00
|
|
|
'expects_that(true).should_not_equal(false) retruned true');
|
2008-12-20 02:13:48 +00:00
|
|
|
|
2009-01-08 01:12:17 +00:00
|
|
|
expected = new Jasmine.Matchers('foobarbel');
|
2008-12-20 02:13:48 +00:00
|
|
|
reporter.test((expected.should_match(/bar/)),
|
|
|
|
'expects_that(forbarbel).should_match(/bar/) returned false');
|
|
|
|
|
|
|
|
expected = new Jasmine.Matchers('foobazbel');
|
|
|
|
reporter.test(!(expected.should_match(/bar/)),
|
|
|
|
'expects_that(forbazbel).should_match(/bar/) returned true');
|
2009-01-08 01:12:17 +00:00
|
|
|
|
|
|
|
expected = new Jasmine.Matchers('foo');
|
|
|
|
reporter.test(expected.should_be_defined(),
|
|
|
|
'expects_that(foo).should_be_defined() returned true');
|
|
|
|
|
|
|
|
expected = new Jasmine.Matchers(undefined);
|
|
|
|
reporter.test(! expected.should_be_defined(),
|
|
|
|
'expects_that(undefined).should_be_defined() returned false');
|
2008-11-30 02:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var testMatchersReporting = function () {
|
|
|
|
|
2008-12-01 23:59:41 +00:00
|
|
|
var results = [];
|
2008-12-08 21:01:06 +00:00
|
|
|
var expected = new Jasmine.Matchers(true, results);
|
2008-12-01 23:59:41 +00:00
|
|
|
expected.should_equal(true);
|
|
|
|
expected.should_equal(false);
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-01 23:59:41 +00:00
|
|
|
reporter.test((results.length == 2),
|
|
|
|
"Results array doesn't have 2 results");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-02 22:26:47 +00:00
|
|
|
reporter.test((results[0].passed === true),
|
2008-12-01 20:26:12 +00:00
|
|
|
"First spec didn't pass");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-02 22:26:47 +00:00
|
|
|
reporter.test((results[1].passed === false),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Second spec did pass");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-01 23:59:41 +00:00
|
|
|
results = [];
|
2008-12-08 21:01:06 +00:00
|
|
|
expected = new Jasmine.Matchers(false, results);
|
2008-12-01 23:59:41 +00:00
|
|
|
expected.should_equal(true);
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-01 23:59:41 +00:00
|
|
|
reporter.test((results[0].message == 'Expected true but got false.'),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Failed expectation didn't test the failure message");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-01 23:59:41 +00:00
|
|
|
results = [];
|
2008-12-08 21:01:06 +00:00
|
|
|
expected = new Jasmine.Matchers(true, results);
|
2008-12-01 23:59:41 +00:00
|
|
|
expected.should_equal(true);
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-01 23:59:41 +00:00
|
|
|
reporter.test((results[0].message == 'Passed.'),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Passing expectation didn't test the passing message");
|
2008-11-30 02:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var testSpecs = function () {
|
2008-12-04 20:54:54 +00:00
|
|
|
var currentSuite = describe('default current suite', function() {
|
|
|
|
});
|
2008-12-04 01:11:05 +00:00
|
|
|
|
2008-11-30 02:12:55 +00:00
|
|
|
var spec = it('new spec');
|
|
|
|
reporter.test((spec.description == 'new spec'),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Spec did not have a description");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-01 23:15:34 +00:00
|
|
|
var another_spec = it('spec with an expectation').runs(function () {
|
2008-11-30 02:12:55 +00:00
|
|
|
var foo = 'bar';
|
2008-12-01 23:59:41 +00:00
|
|
|
this.expects_that(foo).should_equal('bar');
|
2008-11-30 02:12:55 +00:00
|
|
|
});
|
|
|
|
another_spec.execute();
|
2008-12-01 20:26:12 +00:00
|
|
|
another_spec.done = true;
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-02 22:26:47 +00:00
|
|
|
reporter.test((another_spec.results.results.length === 1),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Results aren't there after a spec was executed");
|
2008-12-02 22:26:47 +00:00
|
|
|
reporter.test((another_spec.results.results[0].passed === true),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Results has a result, but it's true");
|
2008-12-02 22:26:47 +00:00
|
|
|
reporter.test((another_spec.results.description === 'spec with an expectation'),
|
|
|
|
"Spec's results did not get the spec's description");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-01 23:15:34 +00:00
|
|
|
var yet_another_spec = it('spec with failing expectation').runs(function () {
|
2008-11-30 02:12:55 +00:00
|
|
|
var foo = 'bar';
|
2008-12-01 23:59:41 +00:00
|
|
|
this.expects_that(foo).should_equal('baz');
|
2008-11-30 02:12:55 +00:00
|
|
|
});
|
|
|
|
yet_another_spec.execute();
|
2008-12-01 23:59:41 +00:00
|
|
|
yet_another_spec.done = true;
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-02 22:26:47 +00:00
|
|
|
reporter.test((yet_another_spec.results.results[0].passed === false),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Expectation that failed, passed");
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-02 00:32:14 +00:00
|
|
|
var yet_yet_another_spec = it('spec with multiple assertions').runs(function () {
|
2008-11-30 02:12:55 +00:00
|
|
|
var foo = 'bar';
|
|
|
|
var baz = 'quux';
|
|
|
|
|
2008-12-01 23:59:41 +00:00
|
|
|
this.expects_that(foo).should_equal('bar');
|
|
|
|
this.expects_that(baz).should_equal('quux');
|
2008-11-30 02:12:55 +00:00
|
|
|
});
|
|
|
|
yet_yet_another_spec.execute();
|
2008-12-01 23:59:41 +00:00
|
|
|
yet_yet_another_spec.done = true;
|
2008-11-30 02:12:55 +00:00
|
|
|
|
2008-12-02 22:26:47 +00:00
|
|
|
reporter.test((yet_yet_another_spec.results.results.length === 2),
|
2008-12-01 20:26:12 +00:00
|
|
|
"Spec doesn't support multiple expectations");
|
|
|
|
}
|
|
|
|
|
|
|
|
var testAsyncSpecs = function () {
|
|
|
|
var foo = 0;
|
|
|
|
|
2008-12-04 00:23:17 +00:00
|
|
|
var a_spec = it('simple queue test', function () {
|
|
|
|
runs(function () {
|
|
|
|
foo++;
|
|
|
|
});
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(foo).should_equal(1)
|
|
|
|
});
|
2008-12-01 20:26:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
reporter.test(a_spec.queue.length === 2,
|
|
|
|
'Spec queue length is not 2');
|
|
|
|
|
|
|
|
foo = 0;
|
2008-12-04 00:23:17 +00:00
|
|
|
a_spec = it('spec w/ queued statments', function () {
|
|
|
|
runs(function () {
|
|
|
|
foo++;
|
|
|
|
});
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(foo).should_equal(1);
|
|
|
|
});
|
2008-12-01 20:26:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
a_spec.execute();
|
|
|
|
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((a_spec.results.results.length === 1),
|
2008-12-01 22:24:13 +00:00
|
|
|
'No call to waits(): Spec queue did not run all functions');
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((a_spec.results.results[0].passed === true),
|
2008-12-01 22:24:13 +00:00
|
|
|
'No call to waits(): Queued expectation failed');
|
2008-12-01 20:26:12 +00:00
|
|
|
|
|
|
|
foo = 0;
|
2008-12-04 00:23:17 +00:00
|
|
|
a_spec = it('spec w/ queued statments', function () {
|
|
|
|
runs(function () {
|
|
|
|
setTimeout(function() {
|
|
|
|
foo++
|
|
|
|
}, 500);
|
|
|
|
});
|
|
|
|
waits(1000);
|
|
|
|
runs(function() {
|
|
|
|
this.expects_that(foo).should_equal(1);
|
|
|
|
});
|
2008-12-02 00:32:14 +00:00
|
|
|
});
|
2008-12-01 20:26:12 +00:00
|
|
|
|
2008-12-02 00:32:14 +00:00
|
|
|
var mockSuite = {
|
|
|
|
next: function() {
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((a_spec.results.results.length === 1),
|
2008-12-02 00:32:14 +00:00
|
|
|
'Calling waits(): Spec queue did not run all functions');
|
2008-12-01 20:26:12 +00:00
|
|
|
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((a_spec.results.results[0].passed === true),
|
2008-12-02 00:32:14 +00:00
|
|
|
'Calling waits(): Queued expectation failed');
|
|
|
|
}
|
|
|
|
};
|
2008-12-08 19:35:10 +00:00
|
|
|
|
2008-12-02 00:32:14 +00:00
|
|
|
a_spec.execute();
|
|
|
|
waitForDone(a_spec, mockSuite);
|
2008-12-01 23:15:34 +00:00
|
|
|
|
2008-12-02 00:32:14 +00:00
|
|
|
var bar = 0;
|
2008-12-04 00:23:17 +00:00
|
|
|
var another_spec = it('spec w/ queued statments', function () {
|
|
|
|
runs(function () {
|
|
|
|
setTimeout(function() {
|
|
|
|
bar++;
|
|
|
|
}, 250);
|
|
|
|
|
|
|
|
});
|
|
|
|
waits(500);
|
|
|
|
runs(function () {
|
|
|
|
setTimeout(function() {
|
|
|
|
bar++;
|
|
|
|
}, 250);
|
|
|
|
});
|
|
|
|
waits(500);
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(bar).should_equal(2);
|
|
|
|
});
|
2008-12-02 00:32:14 +00:00
|
|
|
});
|
2008-12-04 00:23:17 +00:00
|
|
|
|
2008-12-02 00:32:14 +00:00
|
|
|
mockSuite = {
|
|
|
|
next: function() {
|
2008-12-01 23:15:34 +00:00
|
|
|
reporter.test((another_spec.queue.length === 3),
|
|
|
|
'Calling 2 waits(): Spec queue was less than expected length');
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((another_spec.results.results.length === 1),
|
2008-12-01 23:15:34 +00:00
|
|
|
'Calling 2 waits(): Spec queue did not run all functions');
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((another_spec.results.results[0].passed === true),
|
2008-12-01 23:15:34 +00:00
|
|
|
'Calling 2 waits(): Queued expectation failed');
|
2008-12-02 00:32:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
another_spec.execute();
|
|
|
|
waitForDone(another_spec, mockSuite);
|
|
|
|
|
|
|
|
var baz = 0;
|
2008-12-04 00:23:17 +00:00
|
|
|
var yet_another_spec = it('spec w/ async fail', function () {
|
|
|
|
runs(function () {
|
|
|
|
setTimeout(function() {
|
|
|
|
baz++;
|
|
|
|
}, 250);
|
|
|
|
});
|
|
|
|
waits(100);
|
|
|
|
runs(function() {
|
|
|
|
this.expects_that(baz).should_equal(1);
|
|
|
|
});
|
2008-12-02 00:32:14 +00:00
|
|
|
});
|
|
|
|
|
2008-12-04 00:23:17 +00:00
|
|
|
|
2008-12-02 00:32:14 +00:00
|
|
|
mockSuite = {
|
|
|
|
next: function() {
|
2008-12-01 23:15:34 +00:00
|
|
|
|
|
|
|
reporter.test((yet_another_spec.queue.length === 2),
|
|
|
|
'Calling 2 waits(): Spec queue was less than expected length');
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((yet_another_spec.results.results.length === 1),
|
2008-12-01 23:15:34 +00:00
|
|
|
'Calling 2 waits(): Spec queue did not run all functions');
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((yet_another_spec.results.results[0].passed === false),
|
2008-12-01 23:15:34 +00:00
|
|
|
'Calling 2 waits(): Queued expectation failed');
|
2008-12-02 00:32:14 +00:00
|
|
|
}
|
|
|
|
};
|
2008-12-01 23:15:34 +00:00
|
|
|
|
2008-12-02 00:32:14 +00:00
|
|
|
yet_another_spec.execute();
|
|
|
|
waitForDone(yet_another_spec, mockSuite);
|
|
|
|
}
|
|
|
|
|
|
|
|
var testAsyncSpecsWithMockSuite = function () {
|
|
|
|
var bar = 0;
|
2008-12-04 00:23:17 +00:00
|
|
|
var another_spec = it('spec w/ queued statments', function () {
|
|
|
|
runs(function () {
|
|
|
|
setTimeout(function() {
|
|
|
|
bar++;
|
|
|
|
}, 250);
|
|
|
|
});
|
|
|
|
waits(500);
|
|
|
|
runs(function () {
|
|
|
|
setTimeout(function() {
|
|
|
|
bar++;
|
|
|
|
}, 250);
|
|
|
|
});
|
|
|
|
waits(1500)
|
|
|
|
runs(function() {
|
|
|
|
this.expects_that(bar).should_equal(2);
|
|
|
|
});
|
2008-12-02 00:32:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var mockSuite = {
|
|
|
|
next: function () {
|
|
|
|
reporter.test((another_spec.queue.length === 3),
|
|
|
|
'Calling 2 waits(): Spec queue was less than expected length');
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((another_spec.results.results.length === 1),
|
2008-12-02 00:32:14 +00:00
|
|
|
'Calling 2 waits(): Spec queue did not run all functions');
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((another_spec.results.results[0].passed === true),
|
2008-12-02 00:32:14 +00:00
|
|
|
'Calling 2 waits(): Queued expectation failed');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
another_spec.execute();
|
|
|
|
waitForDone(another_spec, mockSuite);
|
|
|
|
}
|
2008-12-01 23:15:34 +00:00
|
|
|
|
2008-12-02 00:32:14 +00:00
|
|
|
var waitForDone = function(spec, mockSuite) {
|
|
|
|
var id = setInterval(function () {
|
|
|
|
if (spec.finished) {
|
|
|
|
clearInterval(id);
|
|
|
|
mockSuite.next();
|
|
|
|
}
|
|
|
|
}, 150);
|
2008-11-30 02:12:55 +00:00
|
|
|
}
|
|
|
|
|
2008-12-02 01:57:21 +00:00
|
|
|
var testSuites = function () {
|
|
|
|
|
|
|
|
// suite has a description
|
2008-12-02 18:27:09 +00:00
|
|
|
var suite = describe('one suite description', function() {
|
|
|
|
});
|
2008-12-02 01:57:21 +00:00
|
|
|
reporter.test((suite.description == 'one suite description'),
|
2008-12-02 18:27:09 +00:00
|
|
|
'Suite did not get a description');
|
2008-12-02 01:57:21 +00:00
|
|
|
|
|
|
|
// suite can have a test
|
|
|
|
suite = describe('one suite description', function () {
|
|
|
|
it('should be a test');
|
|
|
|
});
|
2008-12-02 18:27:09 +00:00
|
|
|
|
|
|
|
reporter.test((suite.specs.length === 1),
|
|
|
|
'Suite did not get a spec pushed');
|
|
|
|
reporter.test((suite.specs[0].queue.length === 0),
|
|
|
|
"Suite's Spec should not have queuedFunctions");
|
|
|
|
|
|
|
|
suite = describe('one suite description', function () {
|
|
|
|
it('should be a test with queuedFunctions', function() {
|
|
|
|
runs(function() {
|
|
|
|
var foo = 0;
|
|
|
|
foo++;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
reporter.test((suite.specs[0].queue.length === 1),
|
|
|
|
"Suite's spec did not get a function pushed");
|
|
|
|
|
|
|
|
suite = describe('one suite description', function () {
|
|
|
|
it('should be a test with queuedFunctions', function() {
|
|
|
|
runs(function() {
|
|
|
|
var foo = 0;
|
|
|
|
foo++;
|
|
|
|
});
|
|
|
|
waits(100);
|
|
|
|
runs(function() {
|
|
|
|
var bar = 0;
|
|
|
|
bar++;
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
reporter.test((suite.specs[0].queue.length === 2),
|
|
|
|
"Suite's spec did not get 2 functions pushed");
|
|
|
|
|
|
|
|
var foo = 0;
|
|
|
|
suite = describe('one suite description', function () {
|
|
|
|
it('should be a test with queuedFunctions', function() {
|
|
|
|
runs(function() {
|
|
|
|
foo++;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be a another spec with queuedFunctions', function() {
|
|
|
|
runs(function() {
|
|
|
|
foo++;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
suite.execute();
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
reporter.test((suite.specs.length === 2),
|
|
|
|
"Suite doesn't have two specs");
|
|
|
|
reporter.test((foo === 2),
|
|
|
|
"Suite didn't execute both specs");
|
|
|
|
}, 500);
|
2008-12-02 01:57:21 +00:00
|
|
|
}
|
|
|
|
|
2008-12-02 23:27:07 +00:00
|
|
|
var testBeforeAndAfterCallbacks = function () {
|
|
|
|
|
|
|
|
var suiteWithBefore = describe('one suite with a before', function () {
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
this.foo = 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be a spec', function () {
|
|
|
|
runs(function() {
|
|
|
|
this.foo++;
|
|
|
|
this.expects_that(this.foo).should_equal(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be another spec', function () {
|
|
|
|
runs(function() {
|
|
|
|
this.foo++;
|
|
|
|
this.expects_that(this.foo).should_equal(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
suiteWithBefore.execute();
|
|
|
|
setTimeout(function () {
|
|
|
|
var suite = suiteWithBefore;
|
|
|
|
reporter.test((suite.beforeEach !== undefined),
|
|
|
|
"Suite's beforeEach was not defined");
|
|
|
|
reporter.test((suite.results.results[0].results[0].passed === true),
|
|
|
|
"the first spec's foo should have been 2");
|
|
|
|
reporter.test((suite.results.results[1].results[0].passed === true),
|
|
|
|
"the second spec's this.foo should have been 2");
|
|
|
|
}, 750);
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
var suiteWithAfter = describe('one suite with an after_each', function () {
|
|
|
|
|
|
|
|
it('should be a spec with an after_each', function () {
|
|
|
|
runs(function() {
|
|
|
|
this.foo = 0;
|
|
|
|
this.foo++;
|
|
|
|
this.expects_that(this.foo).should_equal(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be another spec with an after_each', function () {
|
|
|
|
runs(function() {
|
|
|
|
this.foo = 0;
|
|
|
|
this.foo++;
|
|
|
|
this.expects_that(this.foo).should_equal(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
this.foo = 0;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
suiteWithAfter.execute();
|
|
|
|
setTimeout(function () {
|
|
|
|
var suite = suiteWithAfter;
|
|
|
|
reporter.test((suite.afterEach !== undefined),
|
|
|
|
"Suite's afterEach was not defined");
|
|
|
|
reporter.test((suite.results.results[0].results[0].passed === true),
|
|
|
|
"afterEach failure: " + suite.results.results[0].results[0].message);
|
|
|
|
reporter.test((suite.specs[0].foo === 0),
|
|
|
|
"afterEach failure: foo was not reset to 0");
|
|
|
|
reporter.test((suite.results.results[1].results[0].passed === true),
|
|
|
|
"afterEach failure: " + suite.results.results[0].results[0].message);
|
|
|
|
reporter.test((suite.specs[1].foo === 0),
|
|
|
|
"afterEach failure: foo was not reset to 0");
|
|
|
|
}, 500);
|
|
|
|
}, 1200);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-02 18:27:09 +00:00
|
|
|
var testSpecScope = function () {
|
|
|
|
|
2008-12-08 19:35:10 +00:00
|
|
|
var suite = describe('one suite description', function () {
|
2008-12-02 18:27:09 +00:00
|
|
|
it('should be a test with queuedFunctions', function() {
|
|
|
|
runs(function() {
|
|
|
|
this.foo = 0;
|
|
|
|
this.foo++;
|
|
|
|
});
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
var that = this;
|
|
|
|
setTimeout(function() {
|
|
|
|
that.foo++;
|
|
|
|
}, 250);
|
|
|
|
});
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
this.expects_that(this.foo).should_equal(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
waits(300);
|
|
|
|
|
|
|
|
runs(function() {
|
|
|
|
this.expects_that(this.foo).should_equal(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
suite.execute();
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
reporter.test((suite.specs[0].foo === 2),
|
|
|
|
"Spec does not maintain scope in between functions");
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((suite.specs[0].results.results.length === 2),
|
2008-12-02 18:27:09 +00:00
|
|
|
"Spec did not get results for all expectations");
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((suite.specs[0].results.results[0].passed === false),
|
2008-12-02 18:27:09 +00:00
|
|
|
"Spec did not return false for a failed expectation");
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((suite.specs[0].results.results[1].passed === true),
|
2008-12-02 18:27:09 +00:00
|
|
|
"Spec did not return true for a passing expectation");
|
2008-12-02 22:26:47 +00:00
|
|
|
reporter.test((suite.results.description === 'one suite description'),
|
|
|
|
"Suite did not get its description in the results");
|
2008-12-02 18:27:09 +00:00
|
|
|
}, 1000);
|
|
|
|
}
|
2008-12-02 01:57:21 +00:00
|
|
|
|
2008-12-02 19:08:12 +00:00
|
|
|
|
|
|
|
var testRunner = function() {
|
|
|
|
|
2008-12-04 00:23:17 +00:00
|
|
|
var runner = Runner();
|
2008-12-02 19:08:12 +00:00
|
|
|
describe('one suite description', function () {
|
|
|
|
it('should be a test');
|
|
|
|
});
|
|
|
|
reporter.test((runner.suites.length === 1),
|
2008-12-08 21:01:06 +00:00
|
|
|
"Runner expected one suite, got " + runner.suites.length);
|
2008-12-02 19:08:12 +00:00
|
|
|
|
2008-12-04 00:23:17 +00:00
|
|
|
runner = Runner();
|
2008-12-02 19:08:12 +00:00
|
|
|
describe('one suite description', function () {
|
|
|
|
it('should be a test');
|
|
|
|
});
|
|
|
|
describe('another suite description', function () {
|
|
|
|
it('should be a test');
|
|
|
|
});
|
|
|
|
reporter.test((runner.suites.length === 2),
|
2008-12-04 01:11:05 +00:00
|
|
|
"Runner expected two suites, but got " + runner.suites.length);
|
2008-12-02 19:08:12 +00:00
|
|
|
|
2008-12-04 00:23:17 +00:00
|
|
|
runner = Runner();
|
2008-12-02 19:08:12 +00:00
|
|
|
describe('one suite description', function () {
|
|
|
|
it('should be a test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('another suite description', function () {
|
|
|
|
it('should be another test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.execute();
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
reporter.test((runner.suites.length === 2),
|
2008-12-08 21:01:06 +00:00
|
|
|
"Runner expected two suites, got " + runner.suites.length);
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((runner.suites[0].specs[0].results.results[0].passed === true),
|
2008-12-02 19:08:12 +00:00
|
|
|
"Runner should have run specs in first suite");
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((runner.suites[1].specs[0].results.results[0].passed === false),
|
2008-12-02 19:08:12 +00:00
|
|
|
"Runner should have run specs in second suite");
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
|
2008-12-04 17:37:36 +00:00
|
|
|
var testRunnerFinishCallback = function () {
|
|
|
|
var runner = Runner();
|
|
|
|
var foo = 0;
|
|
|
|
|
|
|
|
runner.finish();
|
|
|
|
|
|
|
|
reporter.test((runner.finished === true),
|
2008-12-04 20:54:54 +00:00
|
|
|
"Runner finished flag was not set.");
|
2008-12-04 17:37:36 +00:00
|
|
|
|
|
|
|
runner.finishCallback = function () {
|
|
|
|
foo++;
|
|
|
|
}
|
|
|
|
|
|
|
|
runner.finish();
|
|
|
|
|
|
|
|
reporter.test((runner.finished === true),
|
2008-12-04 20:54:54 +00:00
|
|
|
"Runner finished flag was not set.");
|
2008-12-04 17:37:36 +00:00
|
|
|
reporter.test((foo === 1),
|
2008-12-04 20:54:54 +00:00
|
|
|
"Runner finish callback was not called");
|
2008-12-04 17:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-02 21:59:39 +00:00
|
|
|
var testNestedResults = function () {
|
|
|
|
|
|
|
|
// Leaf case
|
|
|
|
var results = nestedResults();
|
|
|
|
|
|
|
|
results.push({passed: true, message: 'Passed.'});
|
|
|
|
|
|
|
|
reporter.test((results.results.length === 1),
|
2008-12-02 23:27:07 +00:00
|
|
|
"nestedResults.push didn't work");
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((results.totalCount === 1),
|
2008-12-02 23:27:07 +00:00
|
|
|
"nestedResults.push didn't increment totalCount");
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((results.passedCount === 1),
|
2008-12-02 23:27:07 +00:00
|
|
|
"nestedResults.push didn't increment passedCount");
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((results.failedCount === 0),
|
2008-12-02 23:27:07 +00:00
|
|
|
"nestedResults.push didn't ignore failedCount");
|
2008-12-02 21:59:39 +00:00
|
|
|
|
|
|
|
results.push({passed: false, message: 'FAIL.'});
|
|
|
|
|
|
|
|
reporter.test((results.results.length === 2),
|
2008-12-02 23:27:07 +00:00
|
|
|
"nestedResults.push didn't work");
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((results.totalCount === 2),
|
2008-12-02 23:27:07 +00:00
|
|
|
"nestedResults.push didn't increment totalCount");
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((results.passedCount === 1),
|
2008-12-02 23:27:07 +00:00
|
|
|
"nestedResults.push didn't ignore passedCount");
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((results.failedCount === 1),
|
2008-12-02 23:27:07 +00:00
|
|
|
"nestedResults.push didn't increment failedCount");
|
2008-12-02 21:59:39 +00:00
|
|
|
|
|
|
|
// Branch case
|
|
|
|
var leafResultsOne = nestedResults();
|
|
|
|
leafResultsOne.push({passed: true, message: ''});
|
|
|
|
leafResultsOne.push({passed: false, message: ''});
|
|
|
|
|
|
|
|
var leafResultsTwo = nestedResults();
|
|
|
|
leafResultsTwo.push({passed: true, message: ''});
|
|
|
|
leafResultsTwo.push({passed: false, message: ''});
|
|
|
|
|
|
|
|
var branchResults = nestedResults();
|
|
|
|
branchResults.push(leafResultsOne);
|
|
|
|
branchResults.push(leafResultsTwo);
|
|
|
|
|
|
|
|
reporter.test((branchResults.results.length === 2),
|
2008-12-02 23:27:07 +00:00
|
|
|
"Branch Results should have 2 nestedResults, has " + branchResults.results.length);
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((branchResults.totalCount === 4),
|
2008-12-02 23:27:07 +00:00
|
|
|
"Branch Results should have 4 results, has " + branchResults.totalCount);
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((branchResults.passedCount === 2),
|
2008-12-02 23:27:07 +00:00
|
|
|
"Branch Results should have 2 passed, has " + branchResults.passedCount);
|
2008-12-02 21:59:39 +00:00
|
|
|
reporter.test((branchResults.failedCount === 2),
|
2008-12-02 23:27:07 +00:00
|
|
|
"Branch Results should have 2 failed, has " + branchResults.failedCount);
|
2008-12-02 21:59:39 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 18:56:58 +00:00
|
|
|
var testResults = function () {
|
2008-12-04 00:23:17 +00:00
|
|
|
var runner = Runner();
|
2008-12-02 21:59:39 +00:00
|
|
|
describe('one suite description', function () {
|
|
|
|
it('should be a test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('another suite description', function () {
|
|
|
|
it('should be another test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
runner.execute();
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
reporter.test((runner.results.totalCount === 2),
|
|
|
|
'Expectation count should be 2, but was ' + runner.results.totalCount);
|
|
|
|
reporter.test((runner.results.passedCount === 1),
|
|
|
|
'Expectation Passed count should be 1, but was ' + runner.results.passedCount);
|
|
|
|
reporter.test((runner.results.failedCount === 1),
|
|
|
|
'Expectation Failed count should be 1, but was ' + runner.results.failedCount);
|
2008-12-02 22:26:47 +00:00
|
|
|
reporter.test((runner.results.description === 'All Jasmine Suites'),
|
2008-12-02 23:27:07 +00:00
|
|
|
'Jasmine Runner does not have the expected description, has: ' + runner.results.description);
|
2008-12-08 19:35:10 +00:00
|
|
|
}, 500);
|
2008-12-02 21:59:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-08 19:35:10 +00:00
|
|
|
var testReporterWithCallbacks = function () {
|
2008-12-08 21:01:06 +00:00
|
|
|
jasmine = Jasmine.init();
|
2008-12-04 18:56:58 +00:00
|
|
|
var runner = Runner();
|
2009-01-15 20:40:00 +00:00
|
|
|
|
2008-12-08 19:35:10 +00:00
|
|
|
describe('Suite for JSON Reporter with Callbacks', function () {
|
|
|
|
it('should be a test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('should be a failing test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(false).should_equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('Suite for JSON Reporter with Callbacks 2', function () {
|
2008-12-04 18:56:58 +00:00
|
|
|
it('should be a test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(true);
|
|
|
|
});
|
|
|
|
});
|
2008-12-08 19:35:10 +00:00
|
|
|
|
2008-12-04 18:56:58 +00:00
|
|
|
});
|
|
|
|
|
2008-12-08 21:01:06 +00:00
|
|
|
var foo = 0;
|
|
|
|
var bar = 0;
|
|
|
|
var baz = 0;
|
2008-12-04 18:56:58 +00:00
|
|
|
|
2009-01-15 20:40:00 +00:00
|
|
|
var specCallback = function (results) {
|
|
|
|
foo++;
|
|
|
|
}
|
|
|
|
var suiteCallback = function (results) {
|
|
|
|
bar++;
|
|
|
|
}
|
|
|
|
var runnerCallback = function (results) {
|
|
|
|
baz++;
|
|
|
|
}
|
2008-12-08 19:35:10 +00:00
|
|
|
|
2008-12-08 21:01:06 +00:00
|
|
|
jasmine.reporter = Jasmine.Reporters.reporter({
|
2008-12-08 19:35:10 +00:00
|
|
|
specCallback: specCallback,
|
|
|
|
suiteCallback: suiteCallback,
|
|
|
|
runnerCallback: runnerCallback
|
2008-12-08 21:01:06 +00:00
|
|
|
});
|
2008-12-04 18:56:58 +00:00
|
|
|
runner.execute();
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2008-12-08 19:35:10 +00:00
|
|
|
reporter.test((foo === 3),
|
2008-12-08 21:01:06 +00:00
|
|
|
'foo was expected to be 3, was ' + foo);
|
2008-12-08 19:35:10 +00:00
|
|
|
reporter.test((bar === 2),
|
|
|
|
'bar was expected to be 2, was ' + bar);
|
|
|
|
reporter.test((baz === 1),
|
|
|
|
'baz was expected to be 1, was ' + baz);
|
|
|
|
|
|
|
|
}, 750);
|
2008-12-04 19:45:30 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 19:35:10 +00:00
|
|
|
var testJSONReporter = function () {
|
2008-12-08 21:01:06 +00:00
|
|
|
jasmine = Jasmine.init();
|
2008-12-04 19:45:30 +00:00
|
|
|
var runner = Runner();
|
2008-12-08 21:01:06 +00:00
|
|
|
|
2008-12-08 19:35:10 +00:00
|
|
|
describe('Suite for JSON Reporter, NO DOM', function () {
|
2008-12-04 19:45:30 +00:00
|
|
|
it('should be a test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2008-12-08 21:01:06 +00:00
|
|
|
jasmine.reporter = Jasmine.Reporters.JSON();
|
2008-12-04 19:45:30 +00:00
|
|
|
|
|
|
|
runner.execute();
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2009-01-15 20:40:00 +00:00
|
|
|
var expectedSpecJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}';
|
|
|
|
var expectedSuiteJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter, NO DOM"}';
|
2008-12-08 19:35:10 +00:00
|
|
|
var expectedRunnerJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter, NO DOM"}], "description": "All Jasmine Suites"}';
|
|
|
|
|
2008-12-08 21:01:06 +00:00
|
|
|
specJSON = jasmine.reporter.specJSON;
|
2008-12-08 19:35:10 +00:00
|
|
|
reporter.test((specJSON === expectedSpecJSON),
|
|
|
|
'JSON Reporter does not have the expected Spec results report.<br /> <b>Expected:</b><br /> ' + expectedSpecJSON +
|
|
|
|
'<br /><b>Got:</b><br /> ' + specJSON);
|
|
|
|
|
2008-12-08 21:01:06 +00:00
|
|
|
suiteJSON = jasmine.reporter.suiteJSON;
|
2008-12-08 19:35:10 +00:00
|
|
|
reporter.test((suiteJSON === expectedSuiteJSON),
|
|
|
|
'JSON Reporter does not have the expected Suite results report.<br /> <b>Expected:</b><br /> ' + expectedSuiteJSON +
|
|
|
|
'<br /><b>Got:</b><br /> ' + suiteJSON);
|
|
|
|
|
2008-12-08 21:01:06 +00:00
|
|
|
runnerJSON = jasmine.reporter.runnerJSON;
|
2008-12-08 19:35:10 +00:00
|
|
|
reporter.test((runnerJSON === expectedRunnerJSON),
|
|
|
|
'JSON Reporter does not have the expected Runner results report.<br /> <b>Expected:</b><br /> ' + expectedRunnerJSON +
|
|
|
|
'<br /><b>Got:</b><br /> ' + runnerJSON);
|
2008-12-04 18:56:58 +00:00
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
|
2008-12-08 19:35:10 +00:00
|
|
|
var testJSONReporterWithDOM = function () {
|
2008-12-08 21:01:06 +00:00
|
|
|
jasmine = Jasmine.init();
|
2008-12-08 19:35:10 +00:00
|
|
|
var runner = Runner();
|
2008-12-08 21:01:06 +00:00
|
|
|
|
2008-12-08 19:35:10 +00:00
|
|
|
describe('Suite for JSON Reporter/DOM', function () {
|
|
|
|
it('should be a test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(true);
|
2008-12-04 20:54:54 +00:00
|
|
|
});
|
|
|
|
});
|
2008-12-08 19:35:10 +00:00
|
|
|
});
|
2008-12-04 20:54:54 +00:00
|
|
|
|
2008-12-08 21:01:06 +00:00
|
|
|
jasmine.reporter = Jasmine.Reporters.JSONtoDOM('json_reporter_results');
|
2008-12-08 19:35:10 +00:00
|
|
|
runner.execute();
|
2008-12-04 20:54:54 +00:00
|
|
|
|
2008-12-08 19:35:10 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
var expectedJSONString = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter/DOM"}], "description": "All Jasmine Suites"}';
|
2008-12-04 20:54:54 +00:00
|
|
|
|
2008-12-08 19:35:10 +00:00
|
|
|
reporter.test((document.getElementById('json_reporter_results').innerHTML === expectedJSONString),
|
|
|
|
'JSON Reporter with DOM did not write the expected report to the DOM, got:' + document.getElementById('json_reporter_results').innerHTML);
|
|
|
|
}, 250);
|
2008-12-04 20:54:54 +00:00
|
|
|
}
|
|
|
|
|
2008-12-10 18:30:01 +00:00
|
|
|
var testHandlesBlankSpecs = function () {
|
|
|
|
jasmine = Jasmine.init();
|
|
|
|
var runner = Runner();
|
|
|
|
|
|
|
|
describe('Suite for handles blank specs', function () {
|
|
|
|
it('should be a test with a blank runs block', function() {
|
2009-01-15 20:40:00 +00:00
|
|
|
runs(function () {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('should be a blank (empty function) test', function() {
|
2008-12-10 19:20:33 +00:00
|
|
|
});
|
2009-01-15 20:40:00 +00:00
|
|
|
|
2008-12-10 19:20:33 +00:00
|
|
|
});
|
|
|
|
runner.execute();
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
reporter.test((runner.suites[0].specResults.length === 2),
|
|
|
|
'Should have found 2 spec results, got ' + runner.suites[0].specResults.length);
|
|
|
|
reporter.test((runner.suites[0].results.passedCount === 2),
|
|
|
|
'Should have found 2 passing specs, got ' + runner.suites[0].results.passedCount);
|
|
|
|
}, 250);
|
|
|
|
}
|
|
|
|
|
2009-01-15 20:40:00 +00:00
|
|
|
var testFormatsExceptionMessages = function () {
|
|
|
|
|
|
|
|
var sampleFirefoxException = {
|
|
|
|
fileName: 'foo.js',
|
|
|
|
line: '1978',
|
|
|
|
message: 'you got your foo in my bar',
|
|
|
|
name: 'A Classic Mistake'
|
|
|
|
}
|
|
|
|
|
|
|
|
var sampleWebkitException = {
|
|
|
|
sourceURL: 'foo.js',
|
|
|
|
lineNumber: '1978',
|
|
|
|
message: 'you got your foo in my bar',
|
|
|
|
name: 'A Classic Mistake'
|
|
|
|
}
|
|
|
|
|
|
|
|
var expected = 'A Classic Mistake: you got your foo in my bar in foo.js (line 1978)'
|
|
|
|
|
|
|
|
reporter.test((Jasmine.Util.formatException(sampleFirefoxException) === expected),
|
|
|
|
'Should have got ' + expected + ' but got: ' + Jasmine.Util.formatException(sampleFirefoxException));
|
|
|
|
|
|
|
|
reporter.test((Jasmine.Util.formatException(sampleWebkitException) === expected),
|
|
|
|
'Should have got ' + expected + ' but got: ' + Jasmine.Util.formatException(sampleWebkitException));
|
|
|
|
};
|
|
|
|
|
2008-12-10 19:20:33 +00:00
|
|
|
var testHandlesExceptions = function () {
|
|
|
|
jasmine = Jasmine.init();
|
|
|
|
var runner = Runner();
|
2009-01-15 20:40:00 +00:00
|
|
|
|
|
|
|
//we run two exception tests to make sure we continue after throwing an exception
|
2008-12-10 19:20:33 +00:00
|
|
|
describe('Suite for handles exceptions', function () {
|
|
|
|
it('should be a test that fails because it throws an exception', function() {
|
2008-12-10 18:30:01 +00:00
|
|
|
runs(function () {
|
2008-12-10 19:20:33 +00:00
|
|
|
fakeObject.fakeMethod();
|
2008-12-10 18:30:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2008-12-10 19:20:33 +00:00
|
|
|
it('should be another test that fails because it throws an exception', function() {
|
|
|
|
runs(function () {
|
|
|
|
fakeObject2.fakeMethod2();
|
|
|
|
});
|
2009-01-15 20:40:00 +00:00
|
|
|
runs(function () {
|
2008-12-10 19:20:33 +00:00
|
|
|
this.expects_that(true).should_equal(true);
|
|
|
|
});
|
2008-12-10 18:30:01 +00:00
|
|
|
});
|
2008-12-10 19:20:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
it('should be a passing test that runs after exceptions are thrown', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2009-01-15 22:27:39 +00:00
|
|
|
it('should be another test that fails because it throws an exception after a wait', function() {
|
|
|
|
runs(function () {
|
|
|
|
var foo = 'foo';
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
fakeObject3.fakeMethod();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be a passing test that runs after exceptions are thrown from a async test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(true);
|
|
|
|
});
|
|
|
|
});
|
2009-01-15 20:40:00 +00:00
|
|
|
|
|
|
|
|
2008-12-10 18:30:01 +00:00
|
|
|
});
|
|
|
|
runner.execute();
|
|
|
|
|
|
|
|
setTimeout(function() {
|
2009-01-15 22:27:39 +00:00
|
|
|
reporter.test((runner.suites[0].specResults.length === 5),
|
|
|
|
'Should have found 4 spec results, got ' + runner.suites[0].specResults.length);
|
2008-12-10 19:20:33 +00:00
|
|
|
|
|
|
|
reporter.test((runner.suites[0].specs[0].expectationResults[0].passed === false),
|
|
|
|
'First test should have failed, got passed');
|
|
|
|
|
2009-01-15 20:40:00 +00:00
|
|
|
reporter.test((typeof runner.suites[0].specs[0].expectationResults[0].message.search(/fakeObject/) !== -1),
|
|
|
|
'First test should have contained /fakeObject/, got ' + runner.suites[0].specs[0].expectationResults[0].message);
|
2008-12-10 19:20:33 +00:00
|
|
|
|
|
|
|
reporter.test((runner.suites[0].specs[1].expectationResults[0].passed === false),
|
|
|
|
'Second test should have a failing first result, got passed');
|
|
|
|
|
2009-01-15 20:40:00 +00:00
|
|
|
reporter.test((typeof runner.suites[0].specs[1].expectationResults[0].message.search(/fakeObject2/) !== -1),
|
2009-01-15 22:27:39 +00:00
|
|
|
'Second test should have contained /fakeObject2/, got ' + runner.suites[0].specs[1].expectationResults[0].message);
|
2008-12-10 19:20:33 +00:00
|
|
|
|
|
|
|
reporter.test((runner.suites[0].specs[1].expectationResults[1].passed === true),
|
2009-01-15 20:40:00 +00:00
|
|
|
'Second expectation in second test should have still passed');
|
2008-12-10 19:20:33 +00:00
|
|
|
|
|
|
|
reporter.test((runner.suites[0].specs[2].expectationResults[0].passed === true),
|
|
|
|
'Third test should have passed, got failed');
|
2009-01-15 22:27:39 +00:00
|
|
|
|
|
|
|
reporter.test((runner.suites[0].specs[3].expectationResults[0].passed === false),
|
|
|
|
'Fourth test should have a failing first result, got passed');
|
|
|
|
|
|
|
|
reporter.test((typeof runner.suites[0].specs[3].expectationResults[0].message.search(/fakeObject3/) !== -1),
|
|
|
|
'Fourth test should have contained /fakeObject3/, got ' + runner.suites[0].specs[3].expectationResults[0].message);
|
2008-12-10 19:20:33 +00:00
|
|
|
}, 2000);
|
2008-12-10 18:30:01 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 20:40:00 +00:00
|
|
|
|
2008-12-10 18:30:01 +00:00
|
|
|
var testResultsAliasing = function () {
|
|
|
|
jasmine = Jasmine.init();
|
|
|
|
var runner = Runner();
|
|
|
|
|
|
|
|
describe('Suite for result aliasing test', function () {
|
|
|
|
|
|
|
|
it('should be a test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Suite number two for result aliasing test', function () {
|
|
|
|
it('should be a passing test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be a passing test', function() {
|
|
|
|
runs(function () {
|
|
|
|
this.expects_that(true).should_equal(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
runner.execute();
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
|
|
reporter.test((runner.suiteResults !== undefined),
|
|
|
|
'runner.suiteResults was not defined');
|
|
|
|
|
|
|
|
reporter.test((runner.suiteResults == runner.results.results),
|
|
|
|
'runner.suiteResults should have been ' + Object.toJSON(runner.results.results) +
|
|
|
|
', but was ' + Object.toJSON(runner.suiteResults));
|
|
|
|
|
|
|
|
reporter.test((runner.suiteResults[1] == runner.results.results[1]),
|
|
|
|
'runner.suiteResults should have been ' + Object.toJSON(runner.results.results[1]) +
|
|
|
|
', but was ' + Object.toJSON(runner.suiteResults[1]));
|
|
|
|
|
|
|
|
reporter.test((runner.suites[0].specResults !== undefined),
|
|
|
|
'runner.suites[0].specResults was not defined');
|
|
|
|
|
|
|
|
reporter.test((runner.suites[0].specResults == runner.results.results[0].results),
|
|
|
|
'runner.suites[0].specResults should have been ' + Object.toJSON(runner.results.results[0].results) +
|
|
|
|
', but was ' + Object.toJSON(runner.suites[0].specResults));
|
|
|
|
|
|
|
|
reporter.test((runner.suites[0].specs[0].expectationResults !== undefined),
|
|
|
|
'runner.suites[0].specs[0].expectationResults was not defined');
|
|
|
|
|
|
|
|
reporter.test((runner.suites[0].specs[0].expectationResults == runner.results.results[0].results[0].results),
|
|
|
|
'runner.suites[0].specs[0].expectationResults should have been ' + Object.toJSON(runner.results.results[0].results[0].results) +
|
|
|
|
', but was ' + Object.toJSON(runner.suites[0].specs[0].expectationResults));
|
2009-01-15 20:40:00 +00:00
|
|
|
|
2008-12-10 18:30:01 +00:00
|
|
|
}, 250);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-30 02:12:55 +00:00
|
|
|
var runTests = function () {
|
|
|
|
$('spinner').show();
|
|
|
|
|
2008-12-02 18:27:09 +00:00
|
|
|
testMatchersComparisons();
|
2008-12-02 21:59:39 +00:00
|
|
|
testMatchersReporting();
|
|
|
|
testSpecs();
|
|
|
|
testAsyncSpecs();
|
|
|
|
testAsyncSpecsWithMockSuite();
|
|
|
|
testSuites();
|
2008-12-02 23:27:07 +00:00
|
|
|
testBeforeAndAfterCallbacks();
|
2008-12-02 21:59:39 +00:00
|
|
|
testSpecScope();
|
2008-12-02 19:08:12 +00:00
|
|
|
testRunner();
|
2008-12-04 17:37:36 +00:00
|
|
|
testRunnerFinishCallback();
|
2008-12-02 21:59:39 +00:00
|
|
|
testNestedResults();
|
2008-12-04 18:56:58 +00:00
|
|
|
testResults();
|
2008-12-10 19:20:33 +00:00
|
|
|
// handle blank specs will work later.
|
2009-01-15 20:40:00 +00:00
|
|
|
// testHandlesBlankSpecs();
|
|
|
|
testFormatsExceptionMessages();
|
2008-12-10 19:20:33 +00:00
|
|
|
testHandlesExceptions();
|
|
|
|
testResultsAliasing();
|
2008-12-08 19:35:10 +00:00
|
|
|
|
2008-12-10 19:20:33 +00:00
|
|
|
|
|
|
|
// Timing starts to matter with these tests; ALWAYS use setTimeout()
|
2008-12-08 19:35:10 +00:00
|
|
|
setTimeout(function () {
|
|
|
|
testReporterWithCallbacks();
|
2008-12-10 18:30:01 +00:00
|
|
|
}, 2500);
|
2008-12-08 19:35:10 +00:00
|
|
|
setTimeout(function () {
|
|
|
|
testJSONReporter();
|
2008-12-08 21:01:06 +00:00
|
|
|
}, 3500);
|
2008-12-08 19:35:10 +00:00
|
|
|
setTimeout(function () {
|
|
|
|
testJSONReporterWithDOM();
|
2008-12-08 21:01:06 +00:00
|
|
|
}, 5000);
|
2008-12-02 00:32:14 +00:00
|
|
|
|
2008-12-01 22:24:13 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
$('spinner').hide();
|
|
|
|
reporter.summary();
|
2008-12-08 21:01:06 +00:00
|
|
|
}, 6000);
|
2008-12-01 20:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|