Skip to content

Commit 9400026

Browse files
committed
feat: add "cleanup" function
1 parent 69d1480 commit 9400026

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

src/cleanup.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default function cleanup() {
2+
cleanup.queue.forEach(fn => fn());
3+
cleanup.queue.clear();
4+
}
5+
6+
cleanup.queue = new Set();

src/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
// @flow
22
import act from './act';
3-
import render from './render';
4-
import shallow from './shallow';
5-
import flushMicrotasksQueue from './flushMicrotasksQueue';
3+
import cleanup from './cleanup';
64
import debug from './debug';
75
import fireEvent from './fireEvent';
6+
import flushMicrotasksQueue from './flushMicrotasksQueue';
7+
import render from './render';
8+
import shallow from './shallow';
89
import waitForElement from './waitForElement';
910

10-
export { render };
11-
export { shallow };
12-
export { flushMicrotasksQueue };
11+
export { act };
12+
export { cleanup };
1313
export { debug };
1414
export { fireEvent };
15+
export { flushMicrotasksQueue };
16+
export { render };
17+
export { shallow };
1518
export { waitForElement };
16-
export { act };

src/render.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { queryByAPI } from './helpers/queryByAPI';
77
import a11yAPI from './helpers/a11yAPI';
88
import debugShallow from './helpers/debugShallow';
99
import debugDeep from './helpers/debugDeep';
10+
import cleanup from './cleanup';
1011

1112
type Options = {
1213
wrapper?: React.ComponentType<any>,
@@ -34,6 +35,7 @@ export default function render<T>(
3435
const update = updateWithAct(renderer, wrap);
3536
const instance = renderer.root;
3637

38+
cleanup.queue.add(renderer.unmount);
3739
return {
3840
...getByAPI(instance),
3941
...queryByAPI(instance),

typings/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export declare const shallow: <P = {}>(
135135
instance: ReactTestInstance | React.ReactElement<P>
136136
) => { output: React.ReactElement<P> };
137137
export declare const flushMicrotasksQueue: () => Promise<any>;
138+
export declare const cleanup: () => void;
138139
export declare const debug: DebugAPI;
139140
export declare const fireEvent: FireEventAPI;
140141
export declare const waitForElement: WaitForElementFunction;

0 commit comments

Comments
 (0)