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:
@@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user