@testing-library/react-native 7.1.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +24 -4
  2. package/build/act.js.flow +2 -1
  3. package/build/fireEvent.js +24 -17
  4. package/build/fireEvent.js.flow +36 -28
  5. package/build/flushMicroTasks.js +3 -1
  6. package/build/flushMicroTasks.js.flow +1 -0
  7. package/build/helpers/a11yAPI.js +9 -10
  8. package/build/helpers/a11yAPI.js.flow +10 -12
  9. package/build/helpers/byDisplayValue.js +48 -0
  10. package/build/helpers/byDisplayValue.js.flow +56 -0
  11. package/build/helpers/byPlaceholderText.js +47 -0
  12. package/build/helpers/byPlaceholderText.js.flow +54 -0
  13. package/build/helpers/byTestId.js +36 -0
  14. package/build/helpers/byTestId.js.flow +46 -0
  15. package/build/helpers/byText.js +94 -0
  16. package/build/helpers/byText.js.flow +88 -0
  17. package/build/helpers/debugDeep.js +1 -1
  18. package/build/helpers/debugDeep.js.flow +1 -1
  19. package/build/helpers/debugShallow.js.flow +1 -1
  20. package/build/helpers/errors.js +6 -0
  21. package/build/helpers/errors.js.flow +10 -3
  22. package/build/helpers/filterNodeByType.js +10 -0
  23. package/build/helpers/filterNodeByType.js.flow +1 -0
  24. package/build/helpers/findByAPI.js +14 -46
  25. package/build/helpers/findByAPI.js.flow +43 -58
  26. package/build/helpers/format.js.flow +1 -1
  27. package/build/helpers/getByAPI.js +16 -184
  28. package/build/helpers/getByAPI.js.flow +52 -204
  29. package/build/helpers/{makeQuery.js → makeA11yQuery.js} +2 -2
  30. package/build/helpers/{makeQuery.js.flow → makeA11yQuery.js.flow} +5 -3
  31. package/build/helpers/makeQueries.js +78 -0
  32. package/build/helpers/makeQueries.js.flow +114 -0
  33. package/build/helpers/queryByAPI.js +16 -88
  34. package/build/helpers/queryByAPI.js.flow +57 -90
  35. package/build/helpers/timers.js +77 -0
  36. package/build/helpers/timers.js.flow +88 -0
  37. package/build/index.js +1 -0
  38. package/build/render.js +11 -4
  39. package/build/render.js.flow +32 -8
  40. package/build/shallow.js.flow +1 -1
  41. package/build/types.flow.js.flow +4 -0
  42. package/build/waitFor.js +148 -19
  43. package/build/waitFor.js.flow +159 -18
  44. package/build/waitForElementToBeRemoved.js +3 -1
  45. package/build/waitForElementToBeRemoved.js.flow +3 -2
  46. package/build/within.js +2 -4
  47. package/build/within.js.flow +7 -5
  48. package/jest-preset/index.js +10 -0
  49. package/jest-preset/restore-promise.js +1 -0
  50. package/jest-preset/save-promise.js +1 -0
  51. package/package.json +20 -15
  52. package/typings/index.d.ts +13 -4
@@ -0,0 +1,114 @@
1
+ // @flow
2
+ import waitFor from '../waitFor';
3
+ import type { WaitForOptions } from '../waitFor';
4
+ import { ErrorWithStack } from './errors';
5
+
6
+ type QueryFunction<ArgType, ReturnType> = (
7
+ instance: ReactTestInstance
8
+ ) => (args: ArgType) => ReturnType;
9
+
10
+ type FindQueryFunction<ArgType, ReturnType> = (
11
+ instance: ReactTestInstance
12
+ ) => (args: ArgType, waitForOptions?: WaitForOptions) => Promise<ReturnType>;
13
+
14
+ type QueryAllByQuery<QueryArg> = QueryFunction<
15
+ QueryArg,
16
+ Array<ReactTestInstance>
17
+ >;
18
+ type QueryByQuery<QueryArg> = QueryFunction<QueryArg, null | ReactTestInstance>;
19
+
20
+ type GetAllByQuery<QueryArg> = QueryFunction<
21
+ QueryArg,
22
+ Array<ReactTestInstance>
23
+ >;
24
+ type GetByQuery<QueryArg> = QueryFunction<QueryArg, ReactTestInstance>;
25
+
26
+ type FindAllByQuery<QueryArg> = FindQueryFunction<
27
+ QueryArg,
28
+ Array<ReactTestInstance>
29
+ >;
30
+ type FindByQuery<QueryArg> = FindQueryFunction<QueryArg, ReactTestInstance>;
31
+
32
+ export type Queries<QueryArg> = {
33
+ getBy: GetByQuery<QueryArg>,
34
+ getAllBy: GetAllByQuery<QueryArg>,
35
+ queryBy: QueryByQuery<QueryArg>,
36
+ findBy: FindByQuery<QueryArg>,
37
+ findAllBy: FindAllByQuery<QueryArg>,
38
+ };
39
+
40
+ export function makeQueries<QueryArg>(
41
+ queryAllByQuery: QueryAllByQuery<QueryArg>,
42
+ getMissingError: (args: QueryArg) => string,
43
+ getMultipleError: (args: QueryArg) => string
44
+ ): Queries<QueryArg> {
45
+ function getAllByQuery(instance: ReactTestInstance) {
46
+ return function getAllFn(args: QueryArg) {
47
+ const results = queryAllByQuery(instance)(args);
48
+
49
+ if (results.length === 0) {
50
+ throw new ErrorWithStack(getMissingError(args), getAllFn);
51
+ }
52
+
53
+ return results;
54
+ };
55
+ }
56
+
57
+ function queryByQuery(instance: ReactTestInstance) {
58
+ return function singleQueryFn(args: QueryArg) {
59
+ const results = queryAllByQuery(instance)(args);
60
+
61
+ if (results.length > 1) {
62
+ throw new ErrorWithStack(getMultipleError(args), singleQueryFn);
63
+ }
64
+
65
+ if (results.length === 0) {
66
+ return null;
67
+ }
68
+
69
+ return results[0];
70
+ };
71
+ }
72
+
73
+ function getByQuery(instance: ReactTestInstance) {
74
+ return function getFn(args: QueryArg) {
75
+ const results = queryAllByQuery(instance)(args);
76
+
77
+ if (results.length > 1) {
78
+ throw new ErrorWithStack(getMultipleError(args), getFn);
79
+ }
80
+
81
+ if (results.length === 0) {
82
+ throw new ErrorWithStack(getMissingError(args), getFn);
83
+ }
84
+
85
+ return results[0];
86
+ };
87
+ }
88
+
89
+ function findAllByQuery(instance: ReactTestInstance) {
90
+ return function findAllFn(
91
+ args: QueryArg,
92
+ waitForOptions?: WaitForOptions = {}
93
+ ) {
94
+ return waitFor(() => getAllByQuery(instance)(args), waitForOptions);
95
+ };
96
+ }
97
+
98
+ function findByQuery(instance: ReactTestInstance) {
99
+ return function findFn(
100
+ args: QueryArg,
101
+ waitForOptions?: WaitForOptions = {}
102
+ ) {
103
+ return waitFor(() => getByQuery(instance)(args), waitForOptions);
104
+ };
105
+ }
106
+
107
+ return {
108
+ getBy: getByQuery,
109
+ getAllBy: getAllByQuery,
110
+ queryBy: queryByQuery,
111
+ findBy: findByQuery,
112
+ findAllBy: findAllByQuery,
113
+ };
114
+ }
@@ -3,97 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.queryByAPI = exports.UNSAFE_queryAllByProps = exports.UNSAFE_queryAllByType = exports.UNSAFE_queryByProps = exports.UNSAFE_queryByType = exports.queryAllByTestId = exports.queryAllByDisplayValue = exports.queryAllByPlaceholderText = exports.queryAllByText = exports.queryByTestId = exports.queryByDisplayValue = exports.queryByPlaceholderText = exports.queryByText = void 0;
6
+ exports.queryByAPI = exports.UNSAFE_queryAllByProps = exports.UNSAFE_queryAllByType = exports.UNSAFE_queryByProps = exports.UNSAFE_queryByType = void 0;
7
7
 
8
8
  var React = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _getByAPI = require("./getByAPI");
11
11
 
12
- var _errors = require("./errors");
13
-
14
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
15
-
16
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
18
- const queryByText = instance => function queryByTextFn(text) {
19
- try {
20
- return (0, _getByAPI.getByText)(instance)(text);
21
- } catch (error) {
22
- return (0, _errors.createQueryByError)(error, queryByTextFn);
23
- }
24
- };
25
-
26
- exports.queryByText = queryByText;
27
-
28
- const queryByPlaceholderText = instance => function queryByPlaceholderTextFn(placeholder) {
29
- try {
30
- return (0, _getByAPI.getByPlaceholderText)(instance)(placeholder);
31
- } catch (error) {
32
- return (0, _errors.createQueryByError)(error, queryByPlaceholderTextFn);
33
- }
34
- };
35
-
36
- exports.queryByPlaceholderText = queryByPlaceholderText;
37
-
38
- const queryByDisplayValue = instance => function queryByDisplayValueFn(value) {
39
- try {
40
- return (0, _getByAPI.getByDisplayValue)(instance)(value);
41
- } catch (error) {
42
- return (0, _errors.createQueryByError)(error, queryByDisplayValueFn);
43
- }
44
- };
45
-
46
- exports.queryByDisplayValue = queryByDisplayValue;
47
-
48
- const queryByTestId = instance => function queryByTestIdFn(testID) {
49
- try {
50
- return (0, _getByAPI.getByTestId)(instance)(testID);
51
- } catch (error) {
52
- return (0, _errors.createQueryByError)(error, queryByTestIdFn);
53
- }
54
- };
55
-
56
- exports.queryByTestId = queryByTestId;
57
-
58
- const queryAllByText = instance => text => {
59
- try {
60
- return (0, _getByAPI.getAllByText)(instance)(text);
61
- } catch (error) {
62
- return [];
63
- }
64
- };
12
+ var _byTestId = require("./byTestId");
65
13
 
66
- exports.queryAllByText = queryAllByText;
14
+ var _byText = require("./byText");
67
15
 
68
- const queryAllByPlaceholderText = instance => placeholder => {
69
- try {
70
- return (0, _getByAPI.getAllByPlaceholderText)(instance)(placeholder);
71
- } catch (error) {
72
- return [];
73
- }
74
- };
16
+ var _byPlaceholderText = require("./byPlaceholderText");
75
17
 
76
- exports.queryAllByPlaceholderText = queryAllByPlaceholderText;
18
+ var _byDisplayValue = require("./byDisplayValue");
77
19
 
78
- const queryAllByDisplayValue = instance => value => {
79
- try {
80
- return (0, _getByAPI.getAllByDisplayValue)(instance)(value);
81
- } catch (error) {
82
- return [];
83
- }
84
- };
85
-
86
- exports.queryAllByDisplayValue = queryAllByDisplayValue;
20
+ var _errors = require("./errors");
87
21
 
88
- const queryAllByTestId = instance => testID => {
89
- try {
90
- return (0, _getByAPI.getAllByTestId)(instance)(testID);
91
- } catch (error) {
92
- return [];
93
- }
94
- };
22
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
95
23
 
96
- exports.queryAllByTestId = queryAllByTestId;
24
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
97
25
 
98
26
  const UNSAFE_queryByType = instance => function queryByTypeFn(type) {
99
27
  try {
@@ -136,14 +64,14 @@ const UNSAFE_queryAllByProps = instance => props => {
136
64
  exports.UNSAFE_queryAllByProps = UNSAFE_queryAllByProps;
137
65
 
138
66
  const queryByAPI = instance => ({
139
- queryByTestId: queryByTestId(instance),
140
- queryByText: queryByText(instance),
141
- queryByPlaceholderText: queryByPlaceholderText(instance),
142
- queryByDisplayValue: queryByDisplayValue(instance),
143
- queryAllByTestId: queryAllByTestId(instance),
144
- queryAllByText: queryAllByText(instance),
145
- queryAllByPlaceholderText: queryAllByPlaceholderText(instance),
146
- queryAllByDisplayValue: queryAllByDisplayValue(instance),
67
+ queryByTestId: (0, _byTestId.queryByTestId)(instance),
68
+ queryByText: (0, _byText.queryByText)(instance),
69
+ queryByPlaceholderText: (0, _byPlaceholderText.queryByPlaceholderText)(instance),
70
+ queryByDisplayValue: (0, _byDisplayValue.queryByDisplayValue)(instance),
71
+ queryAllByTestId: (0, _byTestId.queryAllByTestId)(instance),
72
+ queryAllByText: (0, _byText.queryAllByText)(instance),
73
+ queryAllByPlaceholderText: (0, _byPlaceholderText.queryAllByPlaceholderText)(instance),
74
+ queryAllByDisplayValue: (0, _byDisplayValue.queryAllByDisplayValue)(instance),
147
75
  // Unsafe
148
76
  UNSAFE_queryByType: UNSAFE_queryByType(instance),
149
77
  UNSAFE_queryAllByType: UNSAFE_queryAllByType(instance),
@@ -1,102 +1,63 @@
1
1
  // @flow
2
2
  import * as React from 'react';
3
3
  import {
4
- getByTestId,
5
- getByText,
6
- getByPlaceholderText,
7
- getByDisplayValue,
8
- getAllByTestId,
9
- getAllByText,
10
- getAllByPlaceholderText,
11
- getAllByDisplayValue,
12
4
  UNSAFE_getByType,
13
5
  UNSAFE_getByProps,
14
6
  UNSAFE_getAllByType,
15
7
  UNSAFE_getAllByProps,
16
8
  } from './getByAPI';
9
+ import { queryByTestId, queryAllByTestId } from './byTestId';
10
+ import { queryByText, queryAllByText } from './byText';
11
+ import {
12
+ queryByPlaceholderText,
13
+ queryAllByPlaceholderText,
14
+ } from './byPlaceholderText';
15
+ import { queryByDisplayValue, queryAllByDisplayValue } from './byDisplayValue';
17
16
  import {
18
17
  createQueryByError,
19
18
  throwRemovedFunctionError,
20
19
  throwRenamedFunctionError,
21
20
  } from './errors';
22
21
 
23
- export const queryByText = (instance: ReactTestInstance) =>
24
- function queryByTextFn(text: string | RegExp) {
25
- try {
26
- return getByText(instance)(text);
27
- } catch (error) {
28
- return createQueryByError(error, queryByTextFn);
29
- }
30
- };
31
-
32
- export const queryByPlaceholderText = (instance: ReactTestInstance) =>
33
- function queryByPlaceholderTextFn(placeholder: string | RegExp) {
34
- try {
35
- return getByPlaceholderText(instance)(placeholder);
36
- } catch (error) {
37
- return createQueryByError(error, queryByPlaceholderTextFn);
38
- }
39
- };
40
-
41
- export const queryByDisplayValue = (instance: ReactTestInstance) =>
42
- function queryByDisplayValueFn(value: string | RegExp) {
43
- try {
44
- return getByDisplayValue(instance)(value);
45
- } catch (error) {
46
- return createQueryByError(error, queryByDisplayValueFn);
47
- }
48
- };
49
-
50
- export const queryByTestId = (instance: ReactTestInstance) =>
51
- function queryByTestIdFn(testID: string | RegExp) {
52
- try {
53
- return getByTestId(instance)(testID);
54
- } catch (error) {
55
- return createQueryByError(error, queryByTestIdFn);
56
- }
57
- };
58
-
59
- export const queryAllByText = (instance: ReactTestInstance) => (
60
- text: string | RegExp
61
- ) => {
62
- try {
63
- return getAllByText(instance)(text);
64
- } catch (error) {
65
- return [];
66
- }
67
- };
68
-
69
- export const queryAllByPlaceholderText = (instance: ReactTestInstance) => (
70
- placeholder: string | RegExp
71
- ) => {
72
- try {
73
- return getAllByPlaceholderText(instance)(placeholder);
74
- } catch (error) {
75
- return [];
76
- }
77
- };
78
-
79
- export const queryAllByDisplayValue = (instance: ReactTestInstance) => (
80
- value: string | RegExp
81
- ) => {
82
- try {
83
- return getAllByDisplayValue(instance)(value);
84
- } catch (error) {
85
- return [];
86
- }
87
- };
88
-
89
- export const queryAllByTestId = (instance: ReactTestInstance) => (
90
- testID: string | RegExp
91
- ) => {
92
- try {
93
- return getAllByTestId(instance)(testID);
94
- } catch (error) {
95
- return [];
96
- }
97
- };
98
-
99
- export const UNSAFE_queryByType = (instance: ReactTestInstance) =>
22
+ export type QueryByAPI = {|
23
+ queryByText: (name: string | RegExp) => ReactTestInstance | null,
24
+ queryByPlaceholderText: (
25
+ placeholder: string | RegExp
26
+ ) => ReactTestInstance | null,
27
+ queryByDisplayValue: (value: string | RegExp) => ReactTestInstance | null,
28
+ queryByTestId: (testID: string | RegExp) => ReactTestInstance | null,
29
+ queryAllByTestId: (testID: string | RegExp) => Array<ReactTestInstance>,
30
+ queryAllByText: (text: string | RegExp) => Array<ReactTestInstance>,
31
+ queryAllByPlaceholderText: (
32
+ placeholder: string | RegExp
33
+ ) => Array<ReactTestInstance>,
34
+ queryAllByDisplayValue: (value: string | RegExp) => Array<ReactTestInstance>,
35
+
36
+ // Unsafe aliases
37
+ UNSAFE_queryByType: <P>(
38
+ type: React.ComponentType<P>
39
+ ) => ReactTestInstance | null,
40
+ UNSAFE_queryAllByType: <P>(
41
+ type: React.ComponentType<P>
42
+ ) => Array<ReactTestInstance>,
43
+ UNSAFE_queryByProps: (props: { [string]: any }) => ReactTestInstance | null,
44
+ UNSAFE_queryAllByProps: (props: {
45
+ [string]: any,
46
+ }) => Array<ReactTestInstance>,
47
+ queryByName: () => void,
48
+ queryByType: () => void,
49
+ queryByProps: () => void,
50
+ queryAllByName: () => void,
51
+ queryAllByType: () => void,
52
+ queryAllByProps: () => void,
53
+
54
+ queryByPlaceholder: () => void,
55
+ queryAllByPlaceholder: () => void,
56
+ |};
57
+
58
+ export const UNSAFE_queryByType = (
59
+ instance: ReactTestInstance
60
+ ): ((type: React.ComponentType<any>) => ReactTestInstance | null) =>
100
61
  function queryByTypeFn(type: React.ComponentType<any>) {
101
62
  try {
102
63
  return UNSAFE_getByType(instance)(type);
@@ -105,7 +66,9 @@ export const UNSAFE_queryByType = (instance: ReactTestInstance) =>
105
66
  }
106
67
  };
107
68
 
108
- export const UNSAFE_queryByProps = (instance: ReactTestInstance) =>
69
+ export const UNSAFE_queryByProps = (
70
+ instance: ReactTestInstance
71
+ ): ((props: { [propName: string]: any }) => ReactTestInstance | null) =>
109
72
  function queryByPropsFn(props: { [propName: string]: any }) {
110
73
  try {
111
74
  return UNSAFE_getByProps(instance)(props);
@@ -114,7 +77,9 @@ export const UNSAFE_queryByProps = (instance: ReactTestInstance) =>
114
77
  }
115
78
  };
116
79
 
117
- export const UNSAFE_queryAllByType = (instance: ReactTestInstance) => (
80
+ export const UNSAFE_queryAllByType = (
81
+ instance: ReactTestInstance
82
+ ): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) => (
118
83
  type: React.ComponentType<any>
119
84
  ) => {
120
85
  try {
@@ -124,9 +89,11 @@ export const UNSAFE_queryAllByType = (instance: ReactTestInstance) => (
124
89
  }
125
90
  };
126
91
 
127
- export const UNSAFE_queryAllByProps = (instance: ReactTestInstance) => (props: {
92
+ export const UNSAFE_queryAllByProps = (
93
+ instance: ReactTestInstance
94
+ ): ((props: {
128
95
  [propName: string]: any,
129
- }) => {
96
+ }) => Array<ReactTestInstance>) => (props: { [propName: string]: any }) => {
130
97
  try {
131
98
  return UNSAFE_getAllByProps(instance)(props);
132
99
  } catch (error) {
@@ -134,7 +101,7 @@ export const UNSAFE_queryAllByProps = (instance: ReactTestInstance) => (props: {
134
101
  }
135
102
  };
136
103
 
137
- export const queryByAPI = (instance: ReactTestInstance) => ({
104
+ export const queryByAPI = (instance: ReactTestInstance): QueryByAPI => ({
138
105
  queryByTestId: queryByTestId(instance),
139
106
  queryByText: queryByText(instance),
140
107
  queryByPlaceholderText: queryByPlaceholderText(instance),
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.runWithRealTimers = runWithRealTimers;
7
+ exports.setTimeout = exports.setImmediate = exports.clearTimeout = exports.jestFakeTimersAreEnabled = void 0;
8
+ // Most content of this file sourced directly from https://github.com/testing-library/dom-testing-library/blob/main/src/helpers.js
9
+
10
+ /* globals jest */
11
+ const globalObj = typeof window === 'undefined' ? global : window; // Currently this fn only supports jest timers, but it could support other test runners in the future.
12
+
13
+ function runWithRealTimers(callback) {
14
+ const fakeTimersType = getJestFakeTimersType();
15
+
16
+ if (fakeTimersType) {
17
+ jest.useRealTimers();
18
+ }
19
+
20
+ const callbackReturnValue = callback();
21
+
22
+ if (fakeTimersType) {
23
+ jest.useFakeTimers(fakeTimersType);
24
+ }
25
+
26
+ return callbackReturnValue;
27
+ }
28
+
29
+ function getJestFakeTimersType() {
30
+ // istanbul ignore if
31
+ if (typeof jest === 'undefined' || typeof globalObj.setTimeout === 'undefined') {
32
+ return null;
33
+ }
34
+
35
+ if (typeof globalObj.setTimeout._isMockFunction !== 'undefined' && globalObj.setTimeout._isMockFunction) {
36
+ return 'legacy';
37
+ }
38
+
39
+ if (typeof globalObj.setTimeout.clock !== 'undefined' && // $FlowIgnore[prop-missing]
40
+ typeof jest.getRealSystemTime !== 'undefined') {
41
+ try {
42
+ // jest.getRealSystemTime is only supported for Jest's `modern` fake timers and otherwise throws
43
+ // $FlowExpectedError
44
+ jest.getRealSystemTime();
45
+ return 'modern';
46
+ } catch {// not using Jest's modern fake timers
47
+ }
48
+ }
49
+
50
+ return null;
51
+ }
52
+
53
+ const jestFakeTimersAreEnabled = () => Boolean(getJestFakeTimersType()); // we only run our tests in node, and setImmediate is supported in node.
54
+
55
+
56
+ exports.jestFakeTimersAreEnabled = jestFakeTimersAreEnabled;
57
+
58
+ function setImmediatePolyfill(fn) {
59
+ return globalObj.setTimeout(fn, 0);
60
+ }
61
+
62
+ function bindTimeFunctions() {
63
+ return {
64
+ clearTimeoutFn: globalObj.clearTimeout,
65
+ setImmediateFn: globalObj.setImmediate || setImmediatePolyfill,
66
+ setTimeoutFn: globalObj.setTimeout
67
+ };
68
+ }
69
+
70
+ const {
71
+ clearTimeoutFn,
72
+ setImmediateFn,
73
+ setTimeoutFn
74
+ } = runWithRealTimers(bindTimeFunctions);
75
+ exports.setTimeout = setTimeoutFn;
76
+ exports.setImmediate = setImmediateFn;
77
+ exports.clearTimeout = clearTimeoutFn;
@@ -0,0 +1,88 @@
1
+ // Most content of this file sourced directly from https://github.com/testing-library/dom-testing-library/blob/main/src/helpers.js
2
+ // @flow
3
+ /* globals jest */
4
+
5
+ const globalObj = typeof window === 'undefined' ? global : window;
6
+
7
+ // Currently this fn only supports jest timers, but it could support other test runners in the future.
8
+ function runWithRealTimers<T>(callback: () => T): T {
9
+ const fakeTimersType = getJestFakeTimersType();
10
+ if (fakeTimersType) {
11
+ jest.useRealTimers();
12
+ }
13
+
14
+ const callbackReturnValue = callback();
15
+
16
+ if (fakeTimersType) {
17
+ jest.useFakeTimers(fakeTimersType);
18
+ }
19
+
20
+ return callbackReturnValue;
21
+ }
22
+
23
+ function getJestFakeTimersType() {
24
+ // istanbul ignore if
25
+ if (
26
+ typeof jest === 'undefined' ||
27
+ typeof globalObj.setTimeout === 'undefined'
28
+ ) {
29
+ return null;
30
+ }
31
+
32
+ if (
33
+ typeof globalObj.setTimeout._isMockFunction !== 'undefined' &&
34
+ globalObj.setTimeout._isMockFunction
35
+ ) {
36
+ return 'legacy';
37
+ }
38
+
39
+ if (
40
+ typeof globalObj.setTimeout.clock !== 'undefined' &&
41
+ // $FlowIgnore[prop-missing]
42
+ typeof jest.getRealSystemTime !== 'undefined'
43
+ ) {
44
+ try {
45
+ // jest.getRealSystemTime is only supported for Jest's `modern` fake timers and otherwise throws
46
+ // $FlowExpectedError
47
+ jest.getRealSystemTime();
48
+ return 'modern';
49
+ } catch {
50
+ // not using Jest's modern fake timers
51
+ }
52
+ }
53
+ return null;
54
+ }
55
+
56
+ const jestFakeTimersAreEnabled = (): boolean =>
57
+ Boolean(getJestFakeTimersType());
58
+
59
+ // we only run our tests in node, and setImmediate is supported in node.
60
+ function setImmediatePolyfill(fn) {
61
+ return globalObj.setTimeout(fn, 0);
62
+ }
63
+
64
+ type BindTimeFunctions = {
65
+ clearTimeoutFn: typeof clearTimeout,
66
+ setImmediateFn: typeof setImmediate,
67
+ setTimeoutFn: typeof setTimeout,
68
+ };
69
+
70
+ function bindTimeFunctions(): BindTimeFunctions {
71
+ return {
72
+ clearTimeoutFn: globalObj.clearTimeout,
73
+ setImmediateFn: globalObj.setImmediate || setImmediatePolyfill,
74
+ setTimeoutFn: globalObj.setTimeout,
75
+ };
76
+ }
77
+
78
+ const { clearTimeoutFn, setImmediateFn, setTimeoutFn } = (runWithRealTimers(
79
+ bindTimeFunctions
80
+ ): BindTimeFunctions);
81
+
82
+ export {
83
+ runWithRealTimers,
84
+ jestFakeTimersAreEnabled,
85
+ clearTimeoutFn as clearTimeout,
86
+ setImmediateFn as setImmediate,
87
+ setTimeoutFn as setTimeout,
88
+ };
package/build/index.js CHANGED
@@ -8,6 +8,7 @@ var _pure = require("./pure");
8
8
 
9
9
  Object.keys(_pure).forEach(function (key) {
10
10
  if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _pure[key]) return;
11
12
  Object.defineProperty(exports, key, {
12
13
  enumerable: true,
13
14
  get: function () {
package/build/render.js CHANGED
@@ -19,7 +19,7 @@ var _queryByAPI = require("./helpers/queryByAPI");
19
19
 
20
20
  var _findByAPI = require("./helpers/findByAPI");
21
21
 
22
- var _a11yAPI = _interopRequireDefault(require("./helpers/a11yAPI"));
22
+ var _a11yAPI = require("./helpers/a11yAPI");
23
23
 
24
24
  var _debugShallow = _interopRequireDefault(require("./helpers/debugShallow"));
25
25
 
@@ -48,16 +48,23 @@ function render(component, {
48
48
  } : undefined);
49
49
  const update = updateWithAct(renderer, wrap);
50
50
  const instance = renderer.root;
51
- (0, _cleanup.addToCleanupQueue)(renderer.unmount);
51
+
52
+ const unmount = () => {
53
+ (0, _act.default)(() => {
54
+ renderer.unmount();
55
+ });
56
+ };
57
+
58
+ (0, _cleanup.addToCleanupQueue)(unmount);
52
59
  return { ...(0, _getByAPI.getByAPI)(instance),
53
60
  ...(0, _queryByAPI.queryByAPI)(instance),
54
61
  ...(0, _findByAPI.findByAPI)(instance),
55
- ...(0, _a11yAPI.default)(instance),
62
+ ...(0, _a11yAPI.a11yAPI)(instance),
56
63
  update,
64
+ unmount,
57
65
  container: instance,
58
66
  rerender: update,
59
67
  // alias for `update`
60
- unmount: renderer.unmount,
61
68
  toJSON: renderer.toJSON,
62
69
  debug: debug(instance, renderer)
63
70
  };