Support pending specs with:
- xit
- it with a null function body ( it("should be pending");
- calling pending() inside a spec
- having a spec without any expectations
Pending and Filtered specs now call Reporter interface specStarted so that reporting acts as expected.
Pending and Filtered spec names are present and styled in the HTML reporter
Using xit used to disable a spec. Disabling is now just when a spec is filtered out at run time (usually w/ the reporter).
Suites are still disabled with xdescribe and means its specs are never executed.
This commit is contained in:
@@ -58,6 +58,16 @@ describe("ConsoleReporter", function() {
|
||||
expect(out.getOutput()).toEqual("F");
|
||||
});
|
||||
|
||||
it("reports a pending spec as a '*'", function() {
|
||||
var reporter = new jasmine.ConsoleReporter({
|
||||
print: out.print
|
||||
});
|
||||
|
||||
reporter.specDone({status: "pending"});
|
||||
|
||||
expect(out.getOutput()).toEqual("*");
|
||||
});
|
||||
|
||||
it("reports a summary when done (singluar spec and time)", function() {
|
||||
var fakeNow = jasmine.createSpy('fake Date.now'),
|
||||
reporter = new jasmine.ConsoleReporter({
|
||||
@@ -75,6 +85,7 @@ describe("ConsoleReporter", function() {
|
||||
reporter.jasmineDone();
|
||||
|
||||
expect(out.getOutput()).toMatch(/1 spec, 0 failures/);
|
||||
expect(out.getOutput()).not.toMatch(/0 pending specs/);
|
||||
expect(out.getOutput()).toMatch("Finished in 1 second\n");
|
||||
});
|
||||
|
||||
@@ -88,6 +99,7 @@ describe("ConsoleReporter", function() {
|
||||
fakeNow.andReturn(500);
|
||||
reporter.jasmineStarted();
|
||||
reporter.specDone({status: "passed"});
|
||||
reporter.specDone({status: "pending"});
|
||||
reporter.specDone({
|
||||
status: "failed",
|
||||
description: "with a failing spec",
|
||||
@@ -98,9 +110,7 @@ describe("ConsoleReporter", function() {
|
||||
message: "Expected true to be false.",
|
||||
expected: false,
|
||||
actual: true,
|
||||
trace: {
|
||||
stack: "foo\nbar\nbaz"
|
||||
}
|
||||
stack: "foo\nbar\nbaz"
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -110,7 +120,7 @@ describe("ConsoleReporter", function() {
|
||||
fakeNow.andReturn(600);
|
||||
reporter.jasmineDone();
|
||||
|
||||
expect(out.getOutput()).toMatch(/2 specs, 1 failure/);
|
||||
expect(out.getOutput()).toMatch(/3 specs, 1 failure, 1 pending spec/);
|
||||
expect(out.getOutput()).toMatch("Finished in 0.1 seconds\n");
|
||||
});
|
||||
|
||||
@@ -131,9 +141,7 @@ describe("ConsoleReporter", function() {
|
||||
message: "Expected true to be false.",
|
||||
expected: false,
|
||||
actual: true,
|
||||
trace: {
|
||||
stack: "foo bar baz"
|
||||
}
|
||||
stack: "foo bar baz"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
@@ -163,6 +163,29 @@ describe("Env", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#catchException", function() {
|
||||
it("returns true if the exception is a pending spec exception", function() {
|
||||
env.catchExceptions(false);
|
||||
|
||||
expect(env.catchException(new Error(jasmine.Spec.pendingSpecExceptionMessage))).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false if the exception is not a pending spec exception and not catching exceptions", function() {
|
||||
env.catchExceptions(false);
|
||||
|
||||
expect(env.catchException(new Error("external error"))).toBe(false);
|
||||
expect(env.catchException(new Error(jasmine.Spec.pendingSpecExceptionMessage))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#pending", function() {
|
||||
it("throws the Pending Spec exception", function() {
|
||||
expect(function() {
|
||||
env.pending();
|
||||
}).toThrow(jasmine.Spec.pendingSpecExceptionMessage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Env (integration)", function() {
|
||||
@@ -294,7 +317,7 @@ describe("Env (integration)", function() {
|
||||
env.expect(true).toBe(true);
|
||||
});
|
||||
env.describe("with a nested suite", function() {
|
||||
env.xit("with a disabled spec", function() {
|
||||
env.xit("with a pending spec", function() {
|
||||
env.expect(true).toBe(true);
|
||||
});
|
||||
env.it("with a spec", function() {
|
||||
|
||||
@@ -149,26 +149,6 @@ describe("JsApiReporter", function() {
|
||||
expect(suites).toEqual({123: {id: 123, description: "A suite", status: 'passed'}});
|
||||
});
|
||||
|
||||
it("tracks a spec", function() {
|
||||
var reporter = new jasmine.JsApiReporter(),
|
||||
result = {
|
||||
id: 123,
|
||||
description: "A spec"
|
||||
};
|
||||
|
||||
reporter.specStarted(result);
|
||||
|
||||
var specs = reporter.specs();
|
||||
|
||||
expect(specs).toEqual([result]);
|
||||
|
||||
result.status = "passed";
|
||||
|
||||
reporter.specDone(result);
|
||||
|
||||
expect(specs).toEqual([result]);
|
||||
});
|
||||
|
||||
describe("#specResults", function() {
|
||||
var reporter, specResult1, specResult2;
|
||||
beforeEach(function() {
|
||||
@@ -182,8 +162,8 @@ describe("JsApiReporter", function() {
|
||||
description: "Another spec"
|
||||
};
|
||||
|
||||
reporter.specStarted(specResult1);
|
||||
reporter.specStarted(specResult2);
|
||||
reporter.specDone(specResult1);
|
||||
reporter.specDone(specResult2);
|
||||
});
|
||||
|
||||
it("should return a slice of results", function() {
|
||||
|
||||
@@ -96,7 +96,7 @@ describe("QueueRunner", function() {
|
||||
},
|
||||
queueRunner = new jasmine.QueueRunner({
|
||||
fns: [fn],
|
||||
catchingExceptions: function() { return false; }
|
||||
catchException: function(e) { return false; }
|
||||
});
|
||||
|
||||
expect(function() { queueRunner.execute(); }).toThrow();
|
||||
|
||||
@@ -224,7 +224,7 @@ describe("jasmine spec running", function () {
|
||||
var specInADisabledSuite = originalJasmine.createSpy("specInADisabledSuite"),
|
||||
suite = env.describe('A Suite', function() {
|
||||
env.xdescribe('with a disabled suite', function(){
|
||||
env.it('disabled spec', specInADisabledSuite);
|
||||
env.it('spec inside a disabled suite', specInADisabledSuite);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -233,15 +233,18 @@ describe("jasmine spec running", function () {
|
||||
expect(specInADisabledSuite).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("shouldn't run disabled tests", function() {
|
||||
var disabledSpec = originalJasmine.createSpy('disabledSpec'),
|
||||
suite = env.describe('default current suite', function() {
|
||||
env.xit('disabled spec', disabledSpec);
|
||||
});
|
||||
it("should set all pending specs to pending when a suite is run", function() {
|
||||
var pendingSpec,
|
||||
suite = env.describe('default current suite', function() {
|
||||
pendingSpec = env.it("I am a pending spec");
|
||||
});
|
||||
|
||||
suite.execute();
|
||||
expect(disabledSpec).not.toHaveBeenCalled();
|
||||
|
||||
expect(pendingSpec.status()).toBe("pending");
|
||||
});
|
||||
|
||||
|
||||
// TODO: is this useful? It doesn't catch syntax errors
|
||||
xit("should recover gracefully when there are errors in describe functions", function() {
|
||||
var specs = [];
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
describe("Spec", function() {
|
||||
|
||||
it("#isPendingSpecException returns true for a pending spec exception", function() {
|
||||
var e = new Error(jasmine.Spec.pendingSpecExceptionMessage);
|
||||
|
||||
expect(jasmine.Spec.isPendingSpecException(e)).toBe(true);
|
||||
});
|
||||
|
||||
it("#isPendingSpecException returns true for a pending spec exception", function() {
|
||||
var e = new Error("foo");
|
||||
|
||||
expect(jasmine.Spec.isPendingSpecException(e)).toBe(false);
|
||||
});
|
||||
|
||||
it("delegates execution to a QueueRunner", function() {
|
||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
spec = new jasmine.Spec({
|
||||
@@ -78,9 +90,24 @@ describe("Spec", function() {
|
||||
expect(allSpecFns).toEqual([before, fn, after]);
|
||||
});
|
||||
|
||||
it("can be disabled, but still calls callbacks", function() {
|
||||
it("is marked pending if created without a function body", function() {
|
||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
|
||||
startCallback = originalJasmine.createSpy('startCallback'),
|
||||
resultCallback = originalJasmine.createSpy('resultCallback'),
|
||||
spec = new jasmine.Spec({
|
||||
onStart: startCallback,
|
||||
fn: null,
|
||||
resultCallback: resultCallback,
|
||||
queueRunner: fakeQueueRunner
|
||||
});
|
||||
|
||||
|
||||
expect(spec.status()).toBe('pending');
|
||||
});
|
||||
|
||||
it("can be disabled, but still calls callbacks", function() {
|
||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
startCallback = originalJasmine.createSpy('startCallback'),
|
||||
specBody = originalJasmine.createSpy('specBody'),
|
||||
resultCallback = originalJasmine.createSpy('resultCallback'),
|
||||
@@ -97,41 +124,39 @@ describe("Spec", function() {
|
||||
|
||||
spec.execute();
|
||||
|
||||
expect(startCallback).not.toHaveBeenCalled();
|
||||
expect(fakeQueueRunner).not.toHaveBeenCalled();
|
||||
expect(specBody).not.toHaveBeenCalled();
|
||||
|
||||
expect(startCallback).toHaveBeenCalled();
|
||||
expect(resultCallback).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should call the results callback on execution complete", function() {
|
||||
it("can be marked pending, but still calls callbacks when executed", function() {
|
||||
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
|
||||
startCallback = originalJasmine.createSpy('startCallback'),
|
||||
specBody = originalJasmine.createSpy('specBody'),
|
||||
resultCallback = originalJasmine.createSpy('resultCallback'),
|
||||
spec = new jasmine.Spec({
|
||||
onStart:startCallback,
|
||||
fn: specBody,
|
||||
onStart: startCallback,
|
||||
resultCallback: resultCallback,
|
||||
description: "with a spec",
|
||||
getSpecName: function() { return "a suite with a spec"},
|
||||
getSpecName: function() {
|
||||
return "a suite with a spec"
|
||||
},
|
||||
queueRunner: fakeQueueRunner
|
||||
});
|
||||
|
||||
spec.disable();
|
||||
spec.pend();
|
||||
|
||||
expect(spec.status()).toBe('disabled');
|
||||
expect(spec.status()).toBe('pending');
|
||||
|
||||
spec.execute();
|
||||
|
||||
expect(startCallback).not.toHaveBeenCalled();
|
||||
expect(fakeQueueRunner).not.toHaveBeenCalled();
|
||||
expect(specBody).not.toHaveBeenCalled();
|
||||
|
||||
expect(startCallback).toHaveBeenCalled();
|
||||
expect(resultCallback).toHaveBeenCalledWith({
|
||||
id: spec.id,
|
||||
status: 'disabled',
|
||||
status: 'pending',
|
||||
description: 'with a spec',
|
||||
fullName: 'a suite with a spec',
|
||||
failedExpectations: []
|
||||
@@ -152,19 +177,28 @@ describe("Spec", function() {
|
||||
expect(done).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("#status returns null by default", function() {
|
||||
var spec = new jasmine.Spec({});
|
||||
expect(spec.status()).toBeNull();
|
||||
it("#status returns pending by default", function() {
|
||||
var spec = new jasmine.Spec({fn: jasmine.createSpy("spec body")});
|
||||
expect(spec.status()).toEqual('pending');
|
||||
});
|
||||
|
||||
it("#status returns pending if no expectations were encountered", function() {
|
||||
var specBody = jasmine.createSpy("spec body"),
|
||||
spec = new jasmine.Spec({fn: specBody});
|
||||
|
||||
spec.execute();
|
||||
|
||||
expect(spec.status()).toEqual('pending');
|
||||
});
|
||||
|
||||
it("#status returns passed if all expectations in the spec have passed", function() {
|
||||
var spec = new jasmine.Spec({});
|
||||
var spec = new jasmine.Spec({fn: jasmine.createSpy("spec body")});
|
||||
spec.addExpectationResult(true);
|
||||
expect(spec.status()).toBe('passed');
|
||||
});
|
||||
|
||||
it("#status returns failed if any expectations in the spec have failed", function() {
|
||||
var spec = new jasmine.Spec({});
|
||||
var spec = new jasmine.Spec({ fn: jasmine.createSpy("spec body") });
|
||||
spec.addExpectationResult(true);
|
||||
spec.addExpectationResult(false);
|
||||
expect(spec.status()).toBe('failed');
|
||||
@@ -181,4 +215,22 @@ describe("Spec", function() {
|
||||
|
||||
expect(spec.getFullName()).toBe('expected val');
|
||||
});
|
||||
|
||||
describe("when a spec is marked pending during execution", function() {
|
||||
it("should mark the spec as pending", function() {
|
||||
var fakeQueueRunner = function(opts) {
|
||||
opts.onException(new Error(jasmine.Spec.pendingSpecExceptionMessage));
|
||||
},
|
||||
spec = new jasmine.Spec({
|
||||
description: 'my test',
|
||||
id: 'some-id',
|
||||
fn: function() { },
|
||||
queueRunner: fakeQueueRunner
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
|
||||
expect(spec.status()).toEqual("pending");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,8 +37,7 @@ describe("New HtmlReporter", function() {
|
||||
var env = new jasmine.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
@@ -54,12 +53,31 @@ describe("New HtmlReporter", function() {
|
||||
expect(specEl.getAttribute("id")).toEqual("spec_789");
|
||||
});
|
||||
|
||||
it("reports the status symbol of a pending spec", function() {
|
||||
var env = new jasmine.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
reporter.initialize();
|
||||
|
||||
reporter.specDone({id: 789, status: "pending"});
|
||||
|
||||
var statuses = container.getElementsByClassName('symbol-summary')[0];
|
||||
var specEl = statuses.getElementsByTagName('li')[0];
|
||||
expect(specEl.getAttribute("class")).toEqual("pending");
|
||||
expect(specEl.getAttribute("id")).toEqual("spec_789");
|
||||
});
|
||||
|
||||
it("reports the status symbol of a passing spec", function() {
|
||||
var env = new jasmine.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
@@ -79,8 +97,7 @@ describe("New HtmlReporter", function() {
|
||||
var env = new jasmine.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
@@ -108,7 +125,7 @@ describe("New HtmlReporter", function() {
|
||||
fakeNow = jasmine.createSpy('fake Date.now'),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
now: fakeNow,
|
||||
@@ -132,7 +149,7 @@ describe("New HtmlReporter", function() {
|
||||
var env = new jasmine.Env(),
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
@@ -300,12 +317,12 @@ describe("New HtmlReporter", function() {
|
||||
env = new jasmine.Env();
|
||||
container = document.createElement("div");
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
reporter.initialize();
|
||||
|
||||
reporter.jasmineStarted({});
|
||||
@@ -338,6 +355,51 @@ describe("New HtmlReporter", function() {
|
||||
|
||||
expect(specFailure.childNodes.length).toEqual(0);
|
||||
});
|
||||
|
||||
it("reports no pending specs", function() {
|
||||
var alert = container.getElementsByClassName("alert")[0];
|
||||
var alertBars = alert.getElementsByClassName("bar");
|
||||
|
||||
expect(alertBars[0].innerHTML).not.toMatch(/pending spec[s]/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("and there are pending specs", function() {
|
||||
var env, container, reporter;
|
||||
beforeEach(function() {
|
||||
env = new jasmine.Env();
|
||||
container = document.createElement("div");
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
reporter.initialize();
|
||||
|
||||
reporter.jasmineStarted({});
|
||||
reporter.specDone({
|
||||
id: 123,
|
||||
description: "with a spec",
|
||||
fullName: "A Suite with a spec",
|
||||
status: "pending"
|
||||
});
|
||||
reporter.jasmineDone();
|
||||
});
|
||||
|
||||
it("reports the pending specs count", function() {
|
||||
var alert = container.getElementsByClassName("alert")[0];
|
||||
var alertBars = alert.getElementsByClassName("bar");
|
||||
|
||||
expect(alertBars[0].innerHTML).toMatch(/1 spec, 0 failures, 1 pending spec/);
|
||||
});
|
||||
|
||||
it("reports no failure details", function() {
|
||||
var specFailure = container.getElementsByClassName("failures")[0];
|
||||
|
||||
expect(specFailure.childNodes.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("and some tests fail", function() {
|
||||
@@ -345,14 +407,14 @@ describe("New HtmlReporter", function() {
|
||||
|
||||
beforeEach(function() {
|
||||
env = new jasmine.Env();
|
||||
container = document.createElement("div");
|
||||
container = document.createElement("div"),
|
||||
getContainer = function() { return container; },
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
reporter = new jasmine.HtmlReporter({
|
||||
env: env,
|
||||
getContainer: getContainer,
|
||||
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
|
||||
});
|
||||
reporter.initialize();
|
||||
|
||||
reporter.jasmineStarted({});
|
||||
|
||||
Reference in New Issue
Block a user