-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix hook pattern of this.skip() in beforeEach hooks (#3741)
- Loading branch information
Showing
5 changed files
with
157 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 37 additions & 9 deletions
46
test/integration/fixtures/pending/skip-async-beforeEach.fixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,48 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
|
||
describe('skip in beforeEach', function () { | ||
beforeEach(function (done) { | ||
describe('skip in beforeEach', function() { | ||
var runOrder = []; | ||
beforeEach(function(done) { | ||
runOrder.push('beforeEach'); | ||
var self = this; | ||
setTimeout(function () { | ||
setTimeout(function() { | ||
self.skip(); // done() is not required | ||
}, 0); | ||
}, 10); | ||
}); | ||
|
||
it('should skip this test-1', function () { | ||
it('should skip this test-1', function() { | ||
throw new Error('never run this test'); | ||
}); | ||
it('should skip this test-2', function () { | ||
throw new Error('never run this test'); | ||
|
||
describe('inner', function() { | ||
beforeEach(function() { | ||
runOrder.push('should not run'); | ||
}); | ||
|
||
it('should skip this test-2', function() { | ||
throw new Error('never run this test'); | ||
}); | ||
it('should skip this test-3', function() { | ||
throw new Error('never run this test'); | ||
}); | ||
|
||
afterEach(function() { | ||
runOrder.push('should not run'); | ||
}); | ||
}); | ||
it('should skip this test-3', function () { | ||
throw new Error('never run this test'); | ||
|
||
afterEach(function() { | ||
runOrder.push('afterEach'); | ||
}); | ||
after(function() { | ||
runOrder.push('after'); | ||
assert.deepStrictEqual(runOrder, [ | ||
'beforeEach', 'afterEach', | ||
'beforeEach', 'afterEach', | ||
'beforeEach', 'afterEach', | ||
'after' | ||
]); | ||
throw new Error('should throw this error'); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
test/integration/fixtures/pending/skip-sync-beforeEach-cond.fixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
describe('skip conditionally in beforeEach', function() { | ||
var n = 1; | ||
beforeEach(function() { | ||
if (n !== 2) { | ||
this.skip(); | ||
} | ||
}); | ||
|
||
it('should skip this test-1', function() { | ||
throw new Error('never run this test'); | ||
}); | ||
it('should run this test-2', function() {}); | ||
|
||
describe('inner suite', function() { | ||
it('should skip this test-3', function() { | ||
throw new Error('never run this test'); | ||
}); | ||
}); | ||
|
||
afterEach(function() { n++; }); | ||
after(function() { | ||
if (n === 4) { | ||
throw new Error('should throw this error'); | ||
} | ||
}); | ||
}); |
40 changes: 35 additions & 5 deletions
40
test/integration/fixtures/pending/skip-sync-beforeEach.fixture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,45 @@ | ||
'use strict'; | ||
var assert = require('assert'); | ||
|
||
describe('skip in beforeEach', function () { | ||
beforeEach(function () { | ||
describe('skip in beforeEach', function() { | ||
var runOrder = []; | ||
beforeEach(function() { | ||
runOrder.push('beforeEach'); | ||
this.skip(); | ||
}); | ||
|
||
it('should never run this test', function () { | ||
it('should skip this test-1', function() { | ||
throw new Error('never run this test'); | ||
}); | ||
|
||
it('should never run this test', function () { | ||
throw new Error('never run this test'); | ||
describe('inner', function() { | ||
beforeEach(function() { | ||
runOrder.push('should not run'); | ||
}); | ||
|
||
it('should skip this test-2', function() { | ||
throw new Error('never run this test'); | ||
}); | ||
it('should skip this test-3', function() { | ||
throw new Error('never run this test'); | ||
}); | ||
|
||
afterEach(function() { | ||
runOrder.push('should not run'); | ||
}); | ||
}); | ||
|
||
afterEach(function() { | ||
runOrder.push('afterEach'); | ||
}); | ||
after(function() { | ||
runOrder.push('after'); | ||
assert.deepStrictEqual(runOrder, [ | ||
'beforeEach', 'afterEach', | ||
'beforeEach', 'afterEach', | ||
'beforeEach', 'afterEach', | ||
'after' | ||
]); | ||
throw new Error('should throw this error'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters