-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lifecycle hooks] Make afterAll hooks operate in the fashion as after…
…Each. It was discovered that afterAll hooks run in the same order that you add them, while afterEach hooks were running in reverse order. This commit makes their order consistent, and adds regression tests. Relevant issue - #3268
- Loading branch information
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
packages/jest-jasmine2/src/__tests__/integration/lifecycle-hooks-test.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,58 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails oncall+jsinfra | ||
*/ | ||
'use strict'; | ||
|
||
describe('test lifecycle hooks', () => { | ||
const actions = []; | ||
function pushMessage(message) { | ||
return () => { | ||
actions.push(message); | ||
}; | ||
} | ||
|
||
// Validate in an afterAll to prevent previous hooks from firing again. | ||
// Note that when operating correctly, this afterAll will be called last. | ||
afterAll(() => { | ||
const expected = [ | ||
'runner beforeAll1', | ||
'runner beforeAll2', | ||
'runner beforeEach1', | ||
'runner beforeEach2', | ||
'beforeEach1', | ||
'beforeEach2', | ||
'outer it 1', | ||
'afterEach2', | ||
'afterEach1', | ||
'runner afterEach2', | ||
'runner afterEach1', | ||
'runner afterAll2', | ||
'runner afterAll1' | ||
]; | ||
|
||
expect(actions).toEqual(expected); | ||
}); | ||
|
||
beforeAll(pushMessage('runner beforeAll1')); | ||
afterAll(pushMessage('runner afterAll1')); | ||
beforeAll(pushMessage('runner beforeAll2')); | ||
afterAll(pushMessage('runner afterAll2')); | ||
beforeEach(pushMessage('runner beforeEach1')); | ||
afterEach(pushMessage('runner afterEach1')); | ||
beforeEach(pushMessage('runner beforeEach2')); | ||
afterEach(pushMessage('runner afterEach2')); | ||
|
||
describe('Something', () => { | ||
beforeEach(pushMessage('beforeEach1')); | ||
afterEach(pushMessage('afterEach1')); | ||
beforeEach(pushMessage('beforeEach2')); | ||
afterEach(pushMessage('afterEach2')); | ||
it('does it 1', pushMessage('outer it 1')); | ||
}); | ||
}); |
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