File tree Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Expand file tree Collapse file tree 4 files changed +18
-7
lines changed Original file line number Diff line number Diff line change 11import { clearRenderResult } from './screen' ;
22
33type CleanUpFunction = ( ) => void ;
4+ type CleanUpFunctionAsync = ( ) => Promise < void > ;
45
5- const cleanupQueue = new Set < CleanUpFunction > ( ) ;
6+ const cleanupQueue = new Set < CleanUpFunction | CleanUpFunctionAsync > ( ) ;
67
78export default function cleanup ( ) {
89 clearRenderResult ( ) ;
@@ -11,6 +12,16 @@ export default function cleanup() {
1112 cleanupQueue . clear ( ) ;
1213}
1314
14- export function addToCleanupQueue ( fn : CleanUpFunction ) {
15- cleanupQueue . add ( fn ) ;
15+ export async function cleanupAsync ( ) {
16+ clearRenderResult ( ) ;
17+
18+ for ( const fn of cleanupQueue ) {
19+ await fn ( ) ;
20+ }
21+
22+ cleanupQueue . clear ( ) ;
1623}
24+
25+ export function addToCleanupQueue ( fn : CleanUpFunction | CleanUpFunctionAsync ) {
26+ cleanupQueue . add ( fn ) ;
27+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import './matchers/extend-expect';
33
44import { getIsReactActEnvironment , setReactActEnvironment } from './act' ;
55import { flushMicroTasks } from './flush-micro-tasks' ;
6- import { cleanup } from './pure' ;
6+ import { cleanupAsync } from './pure' ;
77
88if ( ! process ?. env ?. RNTL_SKIP_AUTO_CLEANUP ) {
99 // If we're running in a test runner that supports afterEach
@@ -14,7 +14,7 @@ if (!process?.env?.RNTL_SKIP_AUTO_CLEANUP) {
1414 if ( typeof afterEach === 'function' ) {
1515 afterEach ( async ( ) => {
1616 await flushMicroTasks ( ) ;
17- cleanup ( ) ;
17+ await cleanupAsync ( ) ;
1818 } ) ;
1919 }
2020
Original file line number Diff line number Diff line change 11export { default as act } from './act' ;
2- export { default as cleanup } from './cleanup' ;
2+ export { default as cleanup , cleanupAsync } from './cleanup' ;
33export { default as fireEvent , fireEventAsync } from './fire-event' ;
44export { default as render } from './render' ;
55export { default as renderAsync } from './render-async' ;
Original file line number Diff line number Diff line change @@ -124,7 +124,7 @@ function buildRenderResult(
124124 } ) ;
125125 } ;
126126
127- addToCleanupQueue ( unmount ) ;
127+ addToCleanupQueue ( unmountAsync ) ;
128128
129129 const result = {
130130 ...getQueriesForElement ( instance ) ,
You can’t perform that action at this time.
0 commit comments