Skip to content

Commit fdc0bb2

Browse files
author
Andres Ornelas
committed
add test for error in afterEach
1 parent 42257f2 commit fdc0bb2

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

test/scenario/RunnerSpec.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,51 @@ describe('Runner', function(){
7575
it('should execute afterEach after every it', function() {
7676
Describe('describe name', function(){
7777
AfterEach(logger('after;'));
78-
It('should text', logger('body;'));
78+
It('should text1', logger('body1;'));
7979
It('should text2', logger('body2;'));
8080
});
81-
expect(log).toEqual('body;after;body2;after;');
81+
expect(log).toEqual('body1;after;body2;after;');
8282
});
8383

8484
it('should always execute afterEach after every it', function() {
8585
Describe('describe name', function(){
8686
AfterEach(logger('after;'));
8787
It('should text', function() {
88-
log = 'body;';
88+
logger('body1;')();
8989
throw "MyError";
9090
});
9191
It('should text2', logger('body2;'));
9292
});
93-
expect(log).toEqual('body;after;body2;after;');
93+
expect(log).toEqual('body1;after;body2;after;');
94+
});
95+
96+
it('should report an error if afterEach fails', function() {
97+
var next;
98+
Describe('describe name', function(){
99+
AfterEach(function() {
100+
$scenario.addStep('afterEachLog', logger('after;'));
101+
$scenario.addStep('afterEachThrow', function() {
102+
throw "AfterError";
103+
});
104+
});
105+
It('should text1', function() {
106+
$scenario.addStep('step1', logger('step1;'));
107+
});
108+
It('should text2', function() {
109+
$scenario.addStep('step2', logger('step2;'));
110+
});
111+
});
112+
$scenario.run(body);
113+
expect(log).toEqual('step1;after;step2;after;');
114+
expect(scenario.$testrun.results).toEqual([
115+
{ name : 'describe name: it should text1',
116+
passed : false,
117+
error : 'AfterError',
118+
steps : [ 'step1', 'afterEachLog', 'afterEachThrow' ] },
119+
{ name : 'describe name: it should text2',
120+
passed : false,
121+
error : 'AfterError',
122+
steps : [ 'step2', 'afterEachLog', 'afterEachThrow' ] }]);
94123
});
95124
});
96125
});

0 commit comments

Comments
 (0)