-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skip ci] Add support for (before|after)(Each|All) methods (#48820)
Summary: Changelog: [Internal] Add capability to setup / teardown tests Differential Revision: D68454176
- Loading branch information
1 parent
d154cd5
commit 7e7659c
Showing
4 changed files
with
319 additions
and
29 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
51 changes: 51 additions & 0 deletions
51
packages/react-native-fantom/src/__tests__/setup/order-of-execution-itest.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,51 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
const logs: string[] = []; | ||
const log = (message: string): void => { | ||
logs.push(message); | ||
}; | ||
|
||
afterAll(() => { | ||
// Source https://jestjs.io/docs/setup-teardown#order-of-execution | ||
expect(logs).toEqual([ | ||
'describe outer-a', | ||
'describe inner 1', | ||
'describe outer-b', | ||
'describe inner 2', | ||
'describe outer-c', | ||
'test 1', | ||
'test 2', | ||
'test 3', | ||
]); | ||
}); | ||
|
||
describe('describe outer', () => { | ||
log('describe outer-a'); | ||
|
||
describe('describe inner 1', () => { | ||
log('describe inner 1'); | ||
|
||
test('test 1', () => log('test 1')); | ||
}); | ||
|
||
log('describe outer-b'); | ||
|
||
test('test 2', () => log('test 2')); | ||
|
||
describe('describe inner 2', () => { | ||
log('describe inner 2'); | ||
|
||
test('test 3', () => log('test 3')); | ||
}); | ||
|
||
log('describe outer-c'); | ||
}); |
48 changes: 48 additions & 0 deletions
48
packages/react-native-fantom/src/__tests__/setup/order-of-hooks-executions-itest.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,48 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow strict-local | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
const logs: string[] = []; | ||
const log = (message: string): void => { | ||
logs.push(message); | ||
}; | ||
|
||
beforeEach(() => log('connection setup')); | ||
beforeEach(() => log('database setup')); | ||
|
||
afterEach(() => log('database teardown')); | ||
afterEach(() => log('connection teardown')); | ||
afterAll(() => { | ||
// Source https://jestjs.io/docs/setup-teardown#order-of-execution | ||
expect(logs).toEqual([ | ||
'connection setup', | ||
'database setup', | ||
'test 1', | ||
'database teardown', | ||
'connection teardown', | ||
|
||
'connection setup', | ||
'database setup', | ||
'extra database setup', | ||
'test 2', | ||
'extra database teardown', | ||
'database teardown', | ||
'connection teardown', | ||
]); | ||
}); | ||
|
||
test('test 1', () => log('test 1')); | ||
|
||
describe('extra', () => { | ||
beforeEach(() => log('extra database setup')); | ||
afterEach(() => log('extra database teardown')); | ||
|
||
test('test 2', () => log('test 2')); | ||
}); |
Oops, something went wrong.