Rewrite Spec & allow Jasmine to be namespaced
- THere seems to be a performance regression. Large test suites may throw - Regressions: Mock Clock won't install correctly, async specs are temporarily not supported. - Async spec runs/waits interface is gone. Blocks are gone. - Move most global usage into jasmine.Env constructor. - Remove optional 'Jasmine running' from HtmlReporter -- caused NS_FACTORY_ERROR in firefox when tested
This commit is contained in:
@@ -37,566 +37,6 @@ describe("jasmine spec running", function () {
|
||||
expect(it4.id).toEqual(4);
|
||||
});
|
||||
|
||||
it("should build up some objects with results we can inspect", function() {
|
||||
|
||||
var specWithNoBody, specWithExpectation, specWithFailingExpectations, specWithMultipleExpectations;
|
||||
|
||||
var suite = env.describe('default current suite', function() {
|
||||
specWithNoBody = env.it('new spec');
|
||||
|
||||
specWithExpectation = env.it('spec with an expectation').runs(function () {
|
||||
var foo = 'bar';
|
||||
this.expect(foo).toEqual('bar');
|
||||
});
|
||||
|
||||
specWithFailingExpectations = env.it('spec with failing expectation').runs(function () {
|
||||
var foo = 'bar';
|
||||
this.expect(foo).toEqual('baz');
|
||||
});
|
||||
|
||||
specWithMultipleExpectations = env.it('spec with multiple expectations').runs(function () {
|
||||
var foo = 'bar';
|
||||
var baz = 'quux';
|
||||
|
||||
this.expect(foo).toEqual('bar');
|
||||
this.expect(baz).toEqual('quux');
|
||||
});
|
||||
});
|
||||
|
||||
suite.execute();
|
||||
|
||||
expect(specWithNoBody.description).toEqual('new spec');
|
||||
|
||||
expect(specWithExpectation.results().getItems().length).toEqual(1); // "Results aren't there after a spec was executed"
|
||||
expect(specWithExpectation.results().getItems()[0].passed).toEqual(true); // "Results has a result, but it's true"
|
||||
expect(specWithExpectation.results().description).toEqual('spec with an expectation'); // "Spec's results did not get the spec's description"
|
||||
|
||||
expect(specWithFailingExpectations.results().getItems()[0].passed).toEqual(false); // "Expectation that failed, passed"
|
||||
|
||||
expect(specWithMultipleExpectations.results().getItems().length).toEqual(2); // "Spec doesn't support multiple expectations"
|
||||
});
|
||||
|
||||
it("should work without a runs block", function() {
|
||||
var another_spec;
|
||||
env.describe('default current suite', function() {
|
||||
another_spec = env.it('spec with an expectation', function () {
|
||||
var foo = 'bar';
|
||||
this.expect(foo).toEqual('bar');
|
||||
this.expect(foo).toEqual('baz');
|
||||
});
|
||||
});
|
||||
|
||||
another_spec.execute();
|
||||
another_spec.done = true;
|
||||
|
||||
expect(another_spec.results().getItems().length).toEqual(2);
|
||||
expect(another_spec.results().getItems()[0].passed).toEqual(true); // "In a spec without a run block, expected first expectation result to be true but was false"
|
||||
expect(another_spec.results().getItems()[1].passed).toEqual(false); // "In a spec without a run block, expected second expectation result to be false but was true";
|
||||
expect(another_spec.results().description).toEqual('spec with an expectation'); // "In a spec without a run block, results did not include the spec's description";
|
||||
});
|
||||
|
||||
it('should queue waits and runs that it encounters while executing specs', function() {
|
||||
var specWithRunsAndWaits;
|
||||
var foo = 0;
|
||||
env.describe('test async spec', function() {
|
||||
specWithRunsAndWaits = env.it('spec w/ queued statments', function () {
|
||||
this.runs(function () {
|
||||
foo++;
|
||||
});
|
||||
this.waits(500);
|
||||
this.runs(function () {
|
||||
foo++;
|
||||
});
|
||||
this.waits(500);
|
||||
this.runs(function () {
|
||||
foo++;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
expect(foo).toEqual(0);
|
||||
specWithRunsAndWaits.execute();
|
||||
|
||||
expect(foo).toEqual(1);
|
||||
fakeTimer.tick(500);
|
||||
expect(foo).toEqual(2);
|
||||
fakeTimer.tick(500);
|
||||
expect(foo).toEqual(3);
|
||||
});
|
||||
|
||||
it("should run asynchronous tests", function () {
|
||||
var foo = 0;
|
||||
|
||||
var a_spec;
|
||||
env.describe('test async spec', function() {
|
||||
a_spec = env.it('spec w/ queued statments', function () {
|
||||
this.runs(function () {
|
||||
foo++;
|
||||
});
|
||||
this.runs(function () {
|
||||
this.expect(foo).toEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
a_spec.execute();
|
||||
|
||||
expect(a_spec.results().getItems().length).toEqual(1); // 'No call to waits(): Spec queue did not run all functions';
|
||||
expect(a_spec.results().getItems()[0].passed).toEqual(true); // 'No call to waits(): Queued expectation failed';
|
||||
|
||||
foo = 0;
|
||||
env.describe('test async spec', function() {
|
||||
a_spec = env.it('spec w/ queued statments', function () {
|
||||
this.runs(function () {
|
||||
fakeTimer.setTimeout(function() {
|
||||
foo++;
|
||||
}, 500);
|
||||
});
|
||||
this.waits(1000);
|
||||
this.runs(function() {
|
||||
this.expect(foo).toEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
a_spec.execute();
|
||||
|
||||
expect(a_spec.results().getItems().length).toEqual(0);
|
||||
|
||||
fakeTimer.tick(500);
|
||||
expect(a_spec.results().getItems().length).toEqual(0);
|
||||
|
||||
fakeTimer.tick(500);
|
||||
expect(a_spec.results().getItems().length).toEqual(1); // 'Calling waits(): Spec queue did not run all functions';
|
||||
|
||||
expect(a_spec.results().getItems()[0].passed).toEqual(true); // 'Calling waits(): Queued expectation failed';
|
||||
|
||||
var bar = 0;
|
||||
var another_spec;
|
||||
env.describe('test async spec', function() {
|
||||
another_spec = env.it('spec w/ queued statments', function () {
|
||||
this.runs(function () {
|
||||
fakeTimer.setTimeout(function() {
|
||||
bar++;
|
||||
}, 250);
|
||||
|
||||
});
|
||||
this.waits(500);
|
||||
this.runs(function () {
|
||||
fakeTimer.setTimeout(function() {
|
||||
bar++;
|
||||
}, 250);
|
||||
});
|
||||
this.waits(500);
|
||||
this.runs(function () {
|
||||
this.expect(bar).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
another_spec.execute();
|
||||
|
||||
fakeTimer.tick(1000);
|
||||
|
||||
expect(another_spec.results().getItems().length).toEqual(1);
|
||||
expect(another_spec.results().getItems()[0].passed).toEqual(true);
|
||||
|
||||
var baz = 0;
|
||||
var yet_another_spec;
|
||||
env.describe('test async spec', function() {
|
||||
yet_another_spec = env.it('spec w/ async fail', function () {
|
||||
this.runs(function () {
|
||||
fakeTimer.setTimeout(function() {
|
||||
baz++;
|
||||
}, 250);
|
||||
});
|
||||
this.waits(100);
|
||||
this.runs(function() {
|
||||
this.expect(baz).toEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
yet_another_spec.execute();
|
||||
//tick twice so that second runs gets eval'd first: mockClock bug?
|
||||
fakeTimer.tick(100);
|
||||
fakeTimer.tick(150);
|
||||
|
||||
|
||||
expect(yet_another_spec.results().getItems().length).toEqual(1);
|
||||
expect(yet_another_spec.results().getItems()[0].passed).toEqual(false);
|
||||
});
|
||||
|
||||
it("testAsyncSpecsWithMockSuite", function () {
|
||||
var bar = 0;
|
||||
var another_spec;
|
||||
env.describe('test async spec', function() {
|
||||
another_spec = env.it('spec w/ queued statments', function () {
|
||||
this.runs(function () {
|
||||
fakeTimer.setTimeout(function() {
|
||||
bar++;
|
||||
}, 250);
|
||||
});
|
||||
this.waits(500);
|
||||
this.runs(function () {
|
||||
fakeTimer.setTimeout(function() {
|
||||
bar++;
|
||||
}, 250);
|
||||
});
|
||||
this.waits(1500);
|
||||
this.runs(function() {
|
||||
this.expect(bar).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
another_spec.execute();
|
||||
fakeTimer.tick(2000);
|
||||
expect(another_spec.results().getItems().length).toEqual(1);
|
||||
expect(another_spec.results().getItems()[0].passed).toEqual(true);
|
||||
});
|
||||
|
||||
describe("waitsFor", function() {
|
||||
var latchFunction = function() {
|
||||
return true;
|
||||
};
|
||||
var spec;
|
||||
|
||||
function makeWaitsForSpec() {
|
||||
var args = jasmine.util.argsToArray(arguments);
|
||||
env.describe('suite', function() {
|
||||
spec = env.it('spec', function() {
|
||||
this.waitsFor.apply(this, args);
|
||||
});
|
||||
});
|
||||
env.execute();
|
||||
}
|
||||
|
||||
it("should accept args (latchFunction, timeoutMessage, timeout)", function() {
|
||||
makeWaitsForSpec(latchFunction, "message", 123);
|
||||
var block = spec.queue.blocks[1];
|
||||
expect(block.latchFunction).toBe(latchFunction);
|
||||
expect(block.timeout).toEqual(123);
|
||||
expect(block.message).toEqual('message');
|
||||
});
|
||||
|
||||
it("should accept args (latchFunction, timeout)", function() {
|
||||
makeWaitsForSpec(latchFunction, 123);
|
||||
var block = spec.queue.blocks[1];
|
||||
expect(block.latchFunction).toBe(latchFunction);
|
||||
expect(block.timeout).toEqual(123);
|
||||
expect(block.message).toEqual(null);
|
||||
});
|
||||
|
||||
it("should accept args (latchFunction, timeoutMessage)", function() {
|
||||
env.defaultTimeoutInterval = 4321;
|
||||
makeWaitsForSpec(latchFunction, "message");
|
||||
var block = spec.queue.blocks[1];
|
||||
expect(block.latchFunction).toBe(latchFunction);
|
||||
expect(block.timeout).toEqual(4321);
|
||||
expect(block.message).toEqual('message');
|
||||
});
|
||||
|
||||
it("should accept args (latchFunction)", function() {
|
||||
env.defaultTimeoutInterval = 4321;
|
||||
makeWaitsForSpec(latchFunction);
|
||||
var block = spec.queue.blocks[1];
|
||||
expect(block.latchFunction).toBe(latchFunction);
|
||||
expect(block.timeout).toEqual(4321);
|
||||
expect(block.message).toEqual(null);
|
||||
});
|
||||
|
||||
it("should accept deprecated args order (timeout, latchFunction, timeoutMessage)", function() {
|
||||
makeWaitsForSpec(123, latchFunction, "message");
|
||||
var block = spec.queue.blocks[1];
|
||||
expect(block.latchFunction).toBe(latchFunction);
|
||||
expect(block.timeout).toEqual(123);
|
||||
expect(block.message).toEqual('message');
|
||||
});
|
||||
|
||||
it("testWaitsFor", function() {
|
||||
var doneWaiting = false;
|
||||
var runsBlockExecuted = false;
|
||||
|
||||
var spec;
|
||||
env.describe('foo', function() {
|
||||
spec = env.it('has a waits for', function() {
|
||||
this.runs(function() {
|
||||
});
|
||||
|
||||
this.waitsFor(500, function() {
|
||||
return doneWaiting;
|
||||
});
|
||||
|
||||
this.runs(function() {
|
||||
runsBlockExecuted = true;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
expect(runsBlockExecuted).toEqual(false); //, 'should not have executed runs block yet');
|
||||
fakeTimer.tick(100);
|
||||
doneWaiting = true;
|
||||
fakeTimer.tick(100);
|
||||
expect(runsBlockExecuted).toEqual(true); //, 'should have executed runs block');
|
||||
});
|
||||
|
||||
it("fails with message", function() {
|
||||
var spec;
|
||||
env.describe('foo', function() {
|
||||
spec = env.it('has a waits for', function() {
|
||||
this.runs(function() {
|
||||
});
|
||||
|
||||
this.waitsFor(500, function() {
|
||||
return false; // force a timeout
|
||||
}, 'my awesome condition');
|
||||
|
||||
this.runs(function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
fakeTimer.tick(1000);
|
||||
expect(spec.results().getItems()[0].message).toEqual('timeout: timed out after 500 msec waiting for my awesome condition');
|
||||
});
|
||||
|
||||
it("fails and skips the rest of the spec if timeout is reached and the latch function hasn't returned true", function() {
|
||||
var runsBlockExecuted = false;
|
||||
var subsequentSpecRan = false;
|
||||
|
||||
var timeoutSpec, subsequentSpec;
|
||||
var suite = env.describe('foo', function() {
|
||||
timeoutSpec = env.it('has a waits for', function() {
|
||||
this.runs(function() {
|
||||
});
|
||||
|
||||
this.waitsFor(500, function() {
|
||||
return false;
|
||||
});
|
||||
|
||||
this.runs(function() {
|
||||
runsBlockExecuted = true;
|
||||
});
|
||||
});
|
||||
|
||||
subsequentSpec = env.it('then carries on to the next test', function() {
|
||||
subsequentSpecRan = true;
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
expect(runsBlockExecuted).toEqual(false);
|
||||
fakeTimer.tick(100);
|
||||
expect(runsBlockExecuted).toEqual(false);
|
||||
fakeTimer.tick(400);
|
||||
expect(runsBlockExecuted).toEqual(false);
|
||||
expect(timeoutSpec.results().getItems()[0].message).toEqual('timeout: timed out after 500 msec waiting for something to happen');
|
||||
expect(subsequentSpecRan).toEqual(true);
|
||||
});
|
||||
|
||||
it("runs afterEach after timing out", function() {
|
||||
var afterEach = originalJasmine.createSpy('afterEach');
|
||||
|
||||
env.describe('foo', function () {
|
||||
env.afterEach(afterEach);
|
||||
|
||||
env.it('waitsFor', function () {
|
||||
this.waitsFor(100, function() {
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}).execute();
|
||||
|
||||
fakeTimer.tick(500);
|
||||
expect(afterEach).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("runs single-spec after functions after timing out", function() {
|
||||
var after = originalJasmine.createSpy('after');
|
||||
|
||||
env.describe('foo', function () {
|
||||
env.it('waitsFor', function () {
|
||||
this.after(after);
|
||||
this.waitsFor(100, function() {
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}).execute();
|
||||
|
||||
fakeTimer.tick(500);
|
||||
expect(after).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('with consecutive calls', function () {
|
||||
var foo;
|
||||
beforeEach(function () {
|
||||
foo = 0;
|
||||
});
|
||||
|
||||
it('exits immediately (does not stack) if the latchFunction times out', function () {
|
||||
var reachedFirstWaitsFor = false;
|
||||
var reachedSecondWaitsFor = false;
|
||||
env.describe('suite that waits', function () {
|
||||
env.it('should stack timeouts', function() {
|
||||
this.waitsFor(500, function () {
|
||||
reachedFirstWaitsFor = true;
|
||||
return false;
|
||||
});
|
||||
this.waitsFor(500, function () {
|
||||
reachedSecondWaitsFor = true;
|
||||
});
|
||||
this.runs(function () {
|
||||
foo++;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
expect(reachedFirstWaitsFor).toEqual(false);
|
||||
env.execute();
|
||||
|
||||
expect(reachedFirstWaitsFor).toEqual(true);
|
||||
expect(foo).toEqual(0);
|
||||
expect(reachedSecondWaitsFor).toEqual(false);
|
||||
fakeTimer.tick(500);
|
||||
expect(reachedSecondWaitsFor).toEqual(false);
|
||||
expect(foo).toEqual(0);
|
||||
fakeTimer.tick(500);
|
||||
expect(reachedSecondWaitsFor).toEqual(false);
|
||||
expect(foo).toEqual(0);
|
||||
});
|
||||
|
||||
it('stacks latchFunctions', function () {
|
||||
var firstWaitsResult = false;
|
||||
var secondWaitsResult = false;
|
||||
var waitsSuite = env.describe('suite that waits', function () {
|
||||
env.it('spec with waitsFors', function() {
|
||||
this.waitsFor(600, function () {
|
||||
fakeTimer.setTimeout(function () {
|
||||
firstWaitsResult = true;
|
||||
}, 300);
|
||||
return firstWaitsResult;
|
||||
});
|
||||
this.waitsFor(600, function () {
|
||||
fakeTimer.setTimeout(function () {
|
||||
secondWaitsResult = true;
|
||||
}, 300);
|
||||
return secondWaitsResult;
|
||||
});
|
||||
this.runs(function () {
|
||||
foo++;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
expect(firstWaitsResult).toEqual(false);
|
||||
expect(secondWaitsResult).toEqual(false);
|
||||
waitsSuite.execute();
|
||||
|
||||
expect(firstWaitsResult).toEqual(false);
|
||||
expect(secondWaitsResult).toEqual(false);
|
||||
expect(foo).toEqual(0);
|
||||
|
||||
fakeTimer.tick(300);
|
||||
|
||||
expect(firstWaitsResult).toEqual(true);
|
||||
expect(secondWaitsResult).toEqual(false);
|
||||
expect(foo).toEqual(0);
|
||||
|
||||
fakeTimer.tick(300);
|
||||
|
||||
expect(firstWaitsResult).toEqual(true);
|
||||
expect(secondWaitsResult).toEqual(true);
|
||||
expect(foo).toEqual(1);
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("testSpecAfter", function() {
|
||||
var log = "";
|
||||
var spec;
|
||||
var suite = env.describe("has after", function() {
|
||||
spec = env.it('spec with after', function() {
|
||||
this.runs(function() {
|
||||
log += "spec";
|
||||
});
|
||||
});
|
||||
});
|
||||
spec.after(function() {
|
||||
log += "after1";
|
||||
});
|
||||
spec.after(function() {
|
||||
log += "after2";
|
||||
});
|
||||
|
||||
suite.execute();
|
||||
|
||||
expect(log).toEqual("specafter2after1");
|
||||
});
|
||||
|
||||
describe('test suite declaration', function() {
|
||||
var suite;
|
||||
var dummyFunction = function() {
|
||||
};
|
||||
|
||||
it('should give the suite a description', function() {
|
||||
suite = env.describe('one suite description', dummyFunction);
|
||||
expect(suite.description).toEqual('one suite description');
|
||||
});
|
||||
|
||||
it('should enqueue functions for multipart tests and support waits, and run any ready runs() blocks', function() {
|
||||
var foo = 0;
|
||||
var bar = 0;
|
||||
|
||||
suite = env.describe('one suite description', function () {
|
||||
env.it('should be a test with queuedFunctions', function() {
|
||||
this.runs(function() {
|
||||
foo++;
|
||||
});
|
||||
this.waits(100);
|
||||
this.runs(function() {
|
||||
bar++;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite.execute();
|
||||
|
||||
expect(foo).toEqual(1);
|
||||
expect(bar).toEqual(0);
|
||||
|
||||
fakeTimer.tick(100);
|
||||
expect(bar).toEqual(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('#waits should allow consecutive waits calls', function () {
|
||||
var foo = 0;
|
||||
var waitsSuite = env.describe('suite that waits', function () {
|
||||
env.it('should wait', function() {
|
||||
this.waits(500);
|
||||
this.waits(500);
|
||||
this.runs(function () {
|
||||
foo++;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
waitsSuite.execute();
|
||||
expect(foo).toEqual(0);
|
||||
fakeTimer.tick(500);
|
||||
expect(foo).toEqual(0);
|
||||
fakeTimer.tick(500);
|
||||
|
||||
expect(foo).toEqual(1);
|
||||
});
|
||||
|
||||
it('nested suites', function () {
|
||||
|
||||
var foo = 0;
|
||||
@@ -636,183 +76,6 @@ describe("jasmine spec running", function () {
|
||||
expect(quux).toEqual(1);
|
||||
});
|
||||
|
||||
it("#beforeEach should be able to eval runs and waits blocks", function () {
|
||||
var foo = 0;
|
||||
var bar = 0;
|
||||
var suiteWithBefore = env.describe('one suite with a before', function () {
|
||||
this.beforeEach(function () {
|
||||
this.runs(function () {
|
||||
foo++;
|
||||
});
|
||||
this.waits(500);
|
||||
this.runs(function () {
|
||||
foo++;
|
||||
});
|
||||
this.waits(500);
|
||||
});
|
||||
|
||||
env.it('should be a spec', function () {
|
||||
bar = 1;
|
||||
foo++;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
expect(foo).toEqual(0);
|
||||
expect(bar).toEqual(0);
|
||||
suiteWithBefore.execute();
|
||||
|
||||
expect(bar).toEqual(0);
|
||||
expect(foo).toEqual(1);
|
||||
fakeTimer.tick(500);
|
||||
|
||||
expect(bar).toEqual(0);
|
||||
expect(foo).toEqual(2);
|
||||
fakeTimer.tick(500);
|
||||
expect(bar).toEqual(1);
|
||||
expect(foo).toEqual(3);
|
||||
});
|
||||
|
||||
it("#afterEach should be able to eval runs and waits blocks", function () {
|
||||
var foo = 0;
|
||||
var firstSpecHasRun = false;
|
||||
var secondSpecHasRun = false;
|
||||
var suiteWithAfter = env.describe('one suite with a before', function () {
|
||||
this.afterEach(function () {
|
||||
this.waits(500);
|
||||
this.runs(function () {
|
||||
foo++;
|
||||
});
|
||||
this.waits(500);
|
||||
});
|
||||
|
||||
env.it('should be the first spec', function () {
|
||||
firstSpecHasRun = true;
|
||||
});
|
||||
|
||||
env.it('should be a spec', function () {
|
||||
secondSpecHasRun = true;
|
||||
foo++;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
expect(firstSpecHasRun).toEqual(false);
|
||||
expect(secondSpecHasRun).toEqual(false);
|
||||
expect(foo).toEqual(0);
|
||||
|
||||
suiteWithAfter.execute();
|
||||
|
||||
|
||||
expect(firstSpecHasRun).toEqual(true);
|
||||
expect(secondSpecHasRun).toEqual(false);
|
||||
expect(foo).toEqual(0);
|
||||
|
||||
fakeTimer.tick(500);
|
||||
|
||||
expect(foo).toEqual(1);
|
||||
expect(secondSpecHasRun).toEqual(false);
|
||||
fakeTimer.tick(500);
|
||||
|
||||
expect(foo).toEqual(2);
|
||||
expect(secondSpecHasRun).toEqual(true);
|
||||
|
||||
});
|
||||
|
||||
it("Spec#after should be able to eval runs and waits blocks", function () {
|
||||
var runsBeforeAfter = false;
|
||||
var firstSpecHasRun = false;
|
||||
var secondSpecHasRun = false;
|
||||
var afterHasRun = false;
|
||||
var suiteWithAfter = env.describe('one suite with a before', function () {
|
||||
|
||||
env.it('should be the first spec', function () {
|
||||
firstSpecHasRun = true;
|
||||
this.after(function () {
|
||||
this.waits(500);
|
||||
this.runs(function () {
|
||||
afterHasRun = true;
|
||||
});
|
||||
this.waits(500);
|
||||
}, true);
|
||||
this.waits(500);
|
||||
this.runs(function () {
|
||||
runsBeforeAfter = true;
|
||||
});
|
||||
});
|
||||
|
||||
env.it('should be a spec', function () {
|
||||
secondSpecHasRun = true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
expect(firstSpecHasRun).toEqual(false);
|
||||
expect(runsBeforeAfter).toEqual(false);
|
||||
expect(afterHasRun).toEqual(false);
|
||||
expect(secondSpecHasRun).toEqual(false);
|
||||
|
||||
suiteWithAfter.execute();
|
||||
|
||||
expect(firstSpecHasRun).toEqual(true);
|
||||
expect(runsBeforeAfter).toEqual(false);
|
||||
expect(afterHasRun).toEqual(false);
|
||||
expect(secondSpecHasRun).toEqual(false);
|
||||
|
||||
fakeTimer.tick(500);
|
||||
|
||||
expect(firstSpecHasRun).toEqual(true);
|
||||
expect(runsBeforeAfter).toEqual(true);
|
||||
expect(afterHasRun).toEqual(false);
|
||||
expect(secondSpecHasRun).toEqual(false);
|
||||
|
||||
fakeTimer.tick(500);
|
||||
|
||||
expect(firstSpecHasRun).toEqual(true);
|
||||
expect(runsBeforeAfter).toEqual(true);
|
||||
expect(afterHasRun).toEqual(true);
|
||||
expect(secondSpecHasRun).toEqual(false);
|
||||
|
||||
fakeTimer.tick(500);
|
||||
|
||||
expect(firstSpecHasRun).toEqual(true);
|
||||
expect(runsBeforeAfter).toEqual(true);
|
||||
expect(afterHasRun).toEqual(true);
|
||||
expect(secondSpecHasRun).toEqual(true);
|
||||
});
|
||||
|
||||
it("handles waits", function () {
|
||||
var firstSpecHasRun = false;
|
||||
var secondSpecHasRun = false;
|
||||
var suiteWithAfter = env.describe('one suite with a before', function () {
|
||||
|
||||
env.it('should be the first spec', function () {
|
||||
this.waits(500);
|
||||
this.runs(function () {
|
||||
firstSpecHasRun = true;
|
||||
});
|
||||
});
|
||||
|
||||
env.it('should be a spec', function () {
|
||||
secondSpecHasRun = true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
expect(firstSpecHasRun).toEqual(false);
|
||||
expect(secondSpecHasRun).toEqual(false);
|
||||
|
||||
suiteWithAfter.execute();
|
||||
|
||||
expect(firstSpecHasRun).toEqual(false);
|
||||
expect(secondSpecHasRun).toEqual(false);
|
||||
|
||||
fakeTimer.tick(500);
|
||||
|
||||
expect(firstSpecHasRun).toEqual(true);
|
||||
expect(secondSpecHasRun).toEqual(true);
|
||||
});
|
||||
|
||||
it("should permit nested describes", function() {
|
||||
var actions = [];
|
||||
|
||||
@@ -962,43 +225,6 @@ describe("jasmine spec running", function () {
|
||||
expect(actions).toEqual(expected);
|
||||
});
|
||||
|
||||
it("builds up nested names", function() {
|
||||
var nestedSpec;
|
||||
env.describe('Test Subject', function() {
|
||||
env.describe('when under circumstance A', function() {
|
||||
env.describe('and circumstance B', function() {
|
||||
nestedSpec = env.it('behaves thusly', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
expect(nestedSpec.getFullName()).toEqual('Test Subject when under circumstance A and circumstance B behaves thusly.'); //, "Spec.fullName was incorrect: " + nestedSpec.getFullName());
|
||||
});
|
||||
|
||||
it("should bind 'this' to the running spec within the spec body", function() {
|
||||
var specExecuted = jasmine.createSpy(), spec;
|
||||
|
||||
env.describe('Test Subject', function() {
|
||||
spec = env.it('should be a test with queuedFunctions', function() {
|
||||
this.runs(function() {
|
||||
this.foo = 0;
|
||||
expect(this.foo).toBe(0);
|
||||
specExecuted();
|
||||
});
|
||||
|
||||
this.runs(function() {
|
||||
this.foo++;
|
||||
expect(this.foo).toBe(1);
|
||||
specExecuted();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
spec.execute();
|
||||
expect(specExecuted.callCount).toBe(2);
|
||||
});
|
||||
|
||||
it("shouldn't run disabled tests", function() {
|
||||
var disabledSpec = originalJasmine.createSpy('disabledSpec'),
|
||||
suite = env.describe('default current suite', function() {
|
||||
@@ -1008,35 +234,11 @@ describe("jasmine spec running", function () {
|
||||
expect(disabledSpec).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('#explodes should throw an exception when it is called inside a spec', function() {
|
||||
var exceptionMessage = false;
|
||||
var anotherSuite = env.describe('Spec', function () {
|
||||
env.it('plodes', function() {
|
||||
try {
|
||||
this.explodes();
|
||||
}
|
||||
catch (e) {
|
||||
exceptionMessage = e;
|
||||
}
|
||||
expect(exceptionMessage).toNotEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
anotherSuite.execute();
|
||||
|
||||
expect(exceptionMessage).toEqual('explodes function should not have been called');
|
||||
});
|
||||
|
||||
it("should recover gracefully when there are errors in describe functions", function() {
|
||||
var specs = [];
|
||||
var superSimpleReporter = new jasmine.Reporter();
|
||||
superSimpleReporter.reportSpecResults = function(spec) {
|
||||
specs.push("Spec: " + spec.getFullName());
|
||||
var results = spec.results().getItems();
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
var result = results[i];
|
||||
specs.push("Result: " + result.message);
|
||||
}
|
||||
superSimpleReporter.reportSpecResults = function(result) {
|
||||
specs.push("Spec: " + result.fullName);
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -1072,16 +274,12 @@ describe("jasmine spec running", function () {
|
||||
|
||||
expect(specs.join('')).toMatch(new RegExp(
|
||||
'Spec: outer1 inner1 should thingy.' +
|
||||
'Result: Passed.' +
|
||||
'Spec: outer1 inner1 encountered a declaration exception.' +
|
||||
'Result: Error: fake error.*' +
|
||||
'Spec: outer1 inner2 should other thingy.' +
|
||||
'Result: Passed.' +
|
||||
'Spec: outer1 encountered a declaration exception.' +
|
||||
'Result: Error: fake error.*' +
|
||||
'Spec: outer2 should xxx.' +
|
||||
'Result: Passed.'
|
||||
));
|
||||
'Spec: outer1 inner1 encountered a declaration exception.' +
|
||||
'Spec: outer1 inner2 should other thingy.' +
|
||||
'Spec: outer1 encountered a declaration exception.' +
|
||||
'Spec: outer2 should xxx.'
|
||||
));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user