keeping track of passed expectations

This commit is contained in:
Alex Treppass
2014-04-14 14:23:50 +01:00
committed by Sheel Choksi
parent e1e49e8292
commit 5f34be446c
4 changed files with 35 additions and 9 deletions
+6 -3
View File
@@ -263,16 +263,19 @@ getJasmineRequireObj().Spec = function(j$) {
id: this.id, id: this.id,
description: this.description, description: this.description,
fullName: this.getFullName(), fullName: this.getFullName(),
failedExpectations: [] failedExpectations: [],
passedExpectations: []
}; };
} }
Spec.prototype.addExpectationResult = function(passed, data) { Spec.prototype.addExpectationResult = function(passed, data) {
this.expectCalled = true; this.expectCalled = true;
var expectationResult = this.expectationResultFactory(data);
if (passed) { if (passed) {
return; this.result.passedExpectations.push(expectationResult);
} else {
this.result.failedExpectations.push(expectationResult);
} }
this.result.failedExpectations.push(this.expectationResultFactory(data));
}; };
Spec.prototype.expect = function(actual) { Spec.prototype.expect = function(actual) {
+19 -1
View File
@@ -175,7 +175,8 @@ describe("Spec", function() {
status: 'pending', status: 'pending',
description: 'with a spec', description: 'with a spec',
fullName: 'a suite with a spec', fullName: 'a suite with a spec',
failedExpectations: [] failedExpectations: [],
passedExpectations: []
}); });
}); });
@@ -212,6 +213,23 @@ describe("Spec", function() {
expect(spec.status()).toBe('failed'); expect(spec.status()).toBe('failed');
}); });
it("keeps track of passed and failed expectations", function() {
var resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
fn: jasmine.createSpy("spec body"),
expectationResultFactory: function (data) { return data; },
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
resultCallback: resultCallback
});
spec.addExpectationResult(true, 'expectation1');
spec.addExpectationResult(false, 'expectation2');
spec.execute();
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual(['expectation1']);
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual(['expectation2']);
});
it("can return its full name", function() { it("can return its full name", function() {
var specNameSpy = jasmine.createSpy('specNameSpy').and.returnValue('expected val'); var specNameSpy = jasmine.createSpy('specNameSpy').and.returnValue('expected val');
+4 -2
View File
@@ -165,7 +165,8 @@ describe("New HtmlReporter", function() {
reporter.specDone({ reporter.specDone({
id: 345, id: 345,
status: "failed", status: "failed",
failedExpectations: [] failedExpectations: [],
passedExpectations: []
}); });
var specEl = container.querySelector(".symbol-summary li"); var specEl = container.querySelector(".symbol-summary li");
@@ -289,7 +290,8 @@ describe("New HtmlReporter", function() {
description: "with a failing spec", description: "with a failing spec",
fullName: "A Suite inner with a failing spec", fullName: "A Suite inner with a failing spec",
status: "failed", status: "failed",
failedExpectations: [] failedExpectations: [],
passedExpectations: []
}; };
reporter.specStarted(specResult); reporter.specStarted(specResult);
reporter.specDone(specResult); reporter.specDone(specResult);
+6 -3
View File
@@ -23,16 +23,19 @@ getJasmineRequireObj().Spec = function(j$) {
id: this.id, id: this.id,
description: this.description, description: this.description,
fullName: this.getFullName(), fullName: this.getFullName(),
failedExpectations: [] failedExpectations: [],
passedExpectations: []
}; };
} }
Spec.prototype.addExpectationResult = function(passed, data) { Spec.prototype.addExpectationResult = function(passed, data) {
this.expectCalled = true; this.expectCalled = true;
var expectationResult = this.expectationResultFactory(data);
if (passed) { if (passed) {
return; this.result.passedExpectations.push(expectationResult);
} else {
this.result.failedExpectations.push(expectationResult);
} }
this.result.failedExpectations.push(this.expectationResultFactory(data));
}; };
Spec.prototype.expect = function(actual) { Spec.prototype.expect = function(actual) {