Skip afterEach fns in nested suites when a beforeEach fn errors
This matches the behavior of beforeAll errors. * #1533
This commit is contained in:
@@ -11,26 +11,89 @@ describe('CompleteOnFirstErrorSkipPolicy', function() {
|
||||
});
|
||||
|
||||
describe('After something has errored', function() {
|
||||
it('returns the first cleanup fn when called with a non cleanup fn', function() {
|
||||
it('skips non cleanup fns', function() {
|
||||
const fns = arrayOfArbitraryFns(4);
|
||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
||||
arrayOfArbitraryFns(4),
|
||||
fns,
|
||||
2
|
||||
);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(2);
|
||||
expect(policy.skipTo(1)).toEqual(2);
|
||||
expect(policy.skipTo(2)).toEqual(3);
|
||||
expect(policy.skipTo(3)).toEqual(4);
|
||||
});
|
||||
|
||||
it('returns the next index when called with a cleanup fn', function() {
|
||||
describe('When the error was in a beforeEach fn', function() {
|
||||
it('runs cleanup fns defined by the current and containing suites', function() {
|
||||
const parentSuite = { description: 'parentSuite' };
|
||||
const suite = { description: 'suite', parentSuite };
|
||||
const fns = [
|
||||
{
|
||||
suite: suite
|
||||
},
|
||||
{
|
||||
fn: () => {}
|
||||
},
|
||||
{
|
||||
fn: () => {},
|
||||
suite: suite
|
||||
},
|
||||
{
|
||||
fn: () => {},
|
||||
suite: parentSuite
|
||||
}
|
||||
];
|
||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
||||
fns,
|
||||
2
|
||||
);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(2);
|
||||
expect(policy.skipTo(2)).toEqual(3);
|
||||
});
|
||||
|
||||
it('skips cleanup fns defined by nested suites', function() {
|
||||
const parentSuite = { description: 'parentSuite' };
|
||||
const suite = { description: 'suite', parentSuite };
|
||||
const fns = [
|
||||
{
|
||||
fn: () => {},
|
||||
type: 'beforeEach',
|
||||
suite: parentSuite
|
||||
},
|
||||
{
|
||||
fn: () => {}
|
||||
},
|
||||
{
|
||||
fn: () => {},
|
||||
suite: suite
|
||||
},
|
||||
{
|
||||
fn: () => {},
|
||||
suite: parentSuite
|
||||
}
|
||||
];
|
||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
||||
fns,
|
||||
2
|
||||
);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(0)).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('does not skip cleanup fns that have no suite, such as the spec complete fn', function() {
|
||||
const fns = [{ fn: () => {} }, { fn: () => {} }];
|
||||
const policy = new jasmineUnderTest.CompleteOnFirstErrorSkipPolicy(
|
||||
arrayOfArbitraryFns(4),
|
||||
fns,
|
||||
1
|
||||
);
|
||||
|
||||
policy.fnErrored(0);
|
||||
expect(policy.skipTo(1)).toEqual(2);
|
||||
expect(policy.skipTo(2)).toEqual(3);
|
||||
expect(policy.skipTo(0)).toEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,13 +48,16 @@ describe('Suite', function() {
|
||||
env: env,
|
||||
description: 'I am a suite'
|
||||
}),
|
||||
outerBefore = jasmine.createSpy('outerBeforeEach'),
|
||||
innerBefore = jasmine.createSpy('insideBeforeEach');
|
||||
outerBefore = { fn: 'outerBeforeEach' },
|
||||
innerBefore = { fn: 'insideBeforeEach' };
|
||||
|
||||
suite.beforeEach(outerBefore);
|
||||
suite.beforeEach(innerBefore);
|
||||
|
||||
expect(suite.beforeFns).toEqual([innerBefore, outerBefore]);
|
||||
expect(suite.beforeFns).toEqual([
|
||||
{ fn: innerBefore.fn, suite },
|
||||
{ fn: outerBefore.fn, suite }
|
||||
]);
|
||||
});
|
||||
|
||||
it('adds after functions in order of needed execution', function() {
|
||||
@@ -62,13 +65,16 @@ describe('Suite', function() {
|
||||
env: env,
|
||||
description: 'I am a suite'
|
||||
}),
|
||||
outerAfter = jasmine.createSpy('outerAfterEach'),
|
||||
innerAfter = jasmine.createSpy('insideAfterEach');
|
||||
outerAfter = { fn: 'outerAfterEach' },
|
||||
innerAfter = { fn: 'insideAfterEach' };
|
||||
|
||||
suite.afterEach(outerAfter);
|
||||
suite.afterEach(innerAfter);
|
||||
|
||||
expect(suite.afterFns).toEqual([innerAfter, outerAfter]);
|
||||
expect(suite.afterFns).toEqual([
|
||||
{ fn: innerAfter.fn, suite },
|
||||
{ fn: outerAfter.fn, suite }
|
||||
]);
|
||||
});
|
||||
|
||||
it('has a status of failed if any expectations have failed', function() {
|
||||
|
||||
@@ -824,11 +824,7 @@ describe('spec running', function() {
|
||||
});
|
||||
|
||||
env.execute(null, function() {
|
||||
expect(actions).toEqual([
|
||||
'outer beforeEach',
|
||||
'inner afterEach',
|
||||
'outer afterEach'
|
||||
]);
|
||||
expect(actions).toEqual(['outer beforeEach', 'outer afterEach']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -865,11 +861,7 @@ describe('spec running', function() {
|
||||
|
||||
await env.execute();
|
||||
|
||||
expect(actions).toEqual([
|
||||
'outer beforeEach',
|
||||
'inner afterEach',
|
||||
'outer afterEach'
|
||||
]);
|
||||
expect(actions).toEqual(['outer beforeEach', 'outer afterEach']);
|
||||
});
|
||||
|
||||
it('skips to cleanup functions after an expectation failure', async function() {
|
||||
@@ -904,11 +896,7 @@ describe('spec running', function() {
|
||||
|
||||
await env.execute();
|
||||
|
||||
expect(actions).toEqual([
|
||||
'outer beforeEach',
|
||||
'inner afterEach',
|
||||
'outer afterEach'
|
||||
]);
|
||||
expect(actions).toEqual(['outer beforeEach', 'outer afterEach']);
|
||||
});
|
||||
|
||||
it('skips to cleanup functions after done.fail is called', function(done) {
|
||||
@@ -1013,11 +1001,7 @@ describe('spec running', function() {
|
||||
|
||||
await env.execute();
|
||||
|
||||
expect(actions).toEqual([
|
||||
'outer beforeEach',
|
||||
'inner afterEach',
|
||||
'outer afterEach'
|
||||
]);
|
||||
expect(actions).toEqual(['outer beforeEach', 'outer afterEach']);
|
||||
});
|
||||
|
||||
it('skips to cleanup functions after a rejected promise', async function() {
|
||||
@@ -1050,11 +1034,7 @@ describe('spec running', function() {
|
||||
|
||||
await env.execute();
|
||||
|
||||
expect(actions).toEqual([
|
||||
'outer beforeEach',
|
||||
'inner afterEach',
|
||||
'outer afterEach'
|
||||
]);
|
||||
expect(actions).toEqual(['outer beforeEach', 'outer afterEach']);
|
||||
});
|
||||
|
||||
it('does not skip anything after an expectation failure', async function() {
|
||||
@@ -1141,6 +1121,29 @@ describe('spec running', function() {
|
||||
expect(actions).toEqual(['beforeEach', 'afterEach']);
|
||||
});
|
||||
|
||||
it('skips cleanup functions that are defined in child suites when a beforeEach errors', async function() {
|
||||
const parentAfterEachFn = jasmine.createSpy('parentAfterEachFn');
|
||||
const childAfterEachFn = jasmine.createSpy('childAfterEachFn');
|
||||
|
||||
env.describe('parent suite', function() {
|
||||
env.beforeEach(function() {
|
||||
throw new Error('nope');
|
||||
});
|
||||
|
||||
env.afterEach(parentAfterEachFn);
|
||||
|
||||
env.describe('child suite', function() {
|
||||
env.it('a spec', function() {});
|
||||
env.afterEach(childAfterEachFn);
|
||||
});
|
||||
});
|
||||
|
||||
await env.execute();
|
||||
|
||||
expect(parentAfterEachFn).toHaveBeenCalled();
|
||||
expect(childAfterEachFn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('runs all reporter callbacks even if one fails', async function() {
|
||||
var laterReporter = jasmine.createSpyObj('laterReporter', ['specDone']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user