Allow expectations in a global beforeAll or afterAll

- Report afterAll failures in jasmineDone
- Issue #811
This commit is contained in:
Gregg Van Hove
2016-02-25 15:01:47 -08:00
parent 5583b6f954
commit dbd198f7d0
3 changed files with 116 additions and 28 deletions

View File

@@ -708,7 +708,9 @@ getJasmineRequireObj().Env = function(j$) {
var topSuite = new j$.Suite({
env: this,
id: getNextSuiteId(),
description: 'Jasmine__TopLevel__Suite'
description: 'Jasmine__TopLevel__Suite',
expectationFactory: expectationFactory,
expectationResultFactory: expectationResultFactory
});
runnableLookupTable[topSuite.id] = topSuite;
defaultResourcesForRunnable(topSuite.id);
@@ -761,9 +763,15 @@ getJasmineRequireObj().Env = function(j$) {
totalSpecsDefined: totalSpecsDefined
});
currentlyExecutingSuites.push(topSuite);
processor.execute(function() {
clearResourcesForRunnable(topSuite.id);
currentlyExecutingSuites.pop();
reporter.jasmineDone({
order: order
order: order,
failedExpectations: topSuite.result.failedExpectations
});
});
};

View File

@@ -458,33 +458,33 @@ describe("Env integration", function() {
});
it("if there are no specs, it still reports correctly", function(done) {
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('outer suite', [
'Expected 1 to equal 2.',
'Expected 2 to equal 3.'
]);
done();
});
env.addReporter(reporter);
env.describe('outer suite', function() {
env.describe('inner suite', function() {
env.it('spec', function(){ });
});
env.afterAll(function() {
env.expect(1).toEqual(2);
env.expect(2).toEqual(3);
});
});
env.execute();
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('outer suite', [
'Expected 1 to equal 2.',
'Expected 2 to equal 3.'
]);
done();
});
env.addReporter(reporter);
env.describe('outer suite', function() {
env.describe('inner suite', function() {
env.it('spec', function(){ });
});
env.afterAll(function() {
env.expect(1).toEqual(2);
env.expect(2).toEqual(3);
});
});
env.execute();
});
it("reports when afterAll throws an exception", function(done) {
var env = new jasmineUnderTest.Env(),
error = new Error('After All Exception'),
@@ -565,6 +565,53 @@ describe("Env integration", function() {
});
});
it('cascades expecatation failures in global beforeAll down to children', function(done) {
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']);
reporter.jasmineDone.and.callFake(function(results) {
expect(results.failedExpectations).toEqual([]);
expect(reporter.specDone).toHaveFailedExpecationsForRunnable('is a spec', [
'Expected 1 to be 0.'
]);
done();
});
env.beforeAll(function() {
env.expect(1).toBe(0);
});
env.it('is a spec', function() {
env.expect(true).toBe(true);
});
env.addReporter(reporter);
env.execute();
});
it('reports expectation failures in global afterAll', function(done) {
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj(['jasmineDone']);
reporter.jasmineDone.and.callFake(function(results) {
expect(results.failedExpectations).toEqual([jasmine.objectContaining({ message: 'Expected 1 to be 0.' })]);
done();
});
env.afterAll(function() {
env.expect(1).toBe(0);
});
env.it('is a spec', function() {
env.expect(true).toBe(true);
});
env.addReporter(reporter);
env.execute();
});
it("Allows specifying which specs and suites to run", function(done) {
var env = new jasmineUnderTest.Env(),
calls = [],
@@ -760,6 +807,31 @@ describe("Env integration", function() {
env.execute();
});
it('removes a spy from the top suite after the run is complete', function(done) {
var env = new jasmineUnderTest.Env(),
originalFoo = function() {},
testObj = {
foo: originalFoo
};
env.beforeAll(function() {
env.spyOn(testObj, 'foo');
});
env.it('spec', function() {
expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(true);
});
env.addReporter({
jasmineDone: function() {
expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(false);
done();
}
});
env.execute();
});
it("Mock clock can be installed and used in tests", function(done) {
var globalSetTimeout = jasmine.createSpy('globalSetTimeout'),
delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'),

View File

@@ -204,7 +204,9 @@ getJasmineRequireObj().Env = function(j$) {
var topSuite = new j$.Suite({
env: this,
id: getNextSuiteId(),
description: 'Jasmine__TopLevel__Suite'
description: 'Jasmine__TopLevel__Suite',
expectationFactory: expectationFactory,
expectationResultFactory: expectationResultFactory
});
runnableLookupTable[topSuite.id] = topSuite;
defaultResourcesForRunnable(topSuite.id);
@@ -257,9 +259,15 @@ getJasmineRequireObj().Env = function(j$) {
totalSpecsDefined: totalSpecsDefined
});
currentlyExecutingSuites.push(topSuite);
processor.execute(function() {
clearResourcesForRunnable(topSuite.id);
currentlyExecutingSuites.pop();
reporter.jasmineDone({
order: order
order: order,
failedExpectations: topSuite.result.failedExpectations
});
});
};