react 15.3.1-rc.2 → 15.4.0-rc.1

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 (190) hide show
  1. package/dist/react-with-addons.js +3961 -21387
  2. package/dist/react-with-addons.min.js +3 -6
  3. package/dist/react.js +2701 -19464
  4. package/dist/react.min.js +2 -6
  5. package/lib/LinkedStateMixin.js +1 -2
  6. package/lib/PooledClass.js +3 -0
  7. package/lib/ReactAddonsDOMDependencies.js +36 -0
  8. package/lib/ReactAddonsDOMDependenciesUMDShim.js +32 -0
  9. package/lib/ReactCSSTransitionGroup.js +60 -42
  10. package/lib/ReactCSSTransitionGroupChild.js +2 -2
  11. package/lib/ReactClass.js +38 -53
  12. package/lib/ReactComponentTreeHook.js +84 -100
  13. package/lib/{DOMNamespaces.js → ReactComponentTreeHookUMDShim.js} +5 -7
  14. package/lib/ReactCurrentOwner.js +1 -1
  15. package/lib/{renderSubtreeIntoContainer.js → ReactCurrentOwnerUMDShim.js} +6 -4
  16. package/lib/ReactElement.js +6 -29
  17. package/lib/ReactElementSymbol.js +20 -0
  18. package/lib/{ReactDOMComponentFlags.js → ReactElementType.js} +4 -9
  19. package/lib/ReactElementValidator.js +1 -2
  20. package/lib/ReactPropTypeLocationNames.js +1 -0
  21. package/lib/ReactPropTypeLocations.js +2 -11
  22. package/lib/ReactPropTypes.js +30 -13
  23. package/lib/ReactPropTypesSecret.js +1 -0
  24. package/lib/ReactTransitionEvents.js +1 -1
  25. package/lib/ReactTransitionGroup.js +145 -141
  26. package/lib/ReactUMDEntry.js +11 -5
  27. package/lib/{ReactDOMFeatureFlags.js → ReactUMDShim.js} +4 -6
  28. package/lib/ReactVersion.js +1 -1
  29. package/lib/ReactWithAddons.js +15 -2
  30. package/lib/ReactWithAddonsUMDEntry.js +11 -5
  31. package/lib/canDefineProperty.js +2 -0
  32. package/lib/onlyChild.js +1 -1
  33. package/lib/traverseAllChildren.js +11 -2
  34. package/lib/update.js +6 -7
  35. package/package.json +2 -2
  36. package/lib/AutoFocusUtils.js +0 -24
  37. package/lib/BeforeInputEventPlugin.js +0 -388
  38. package/lib/CSSProperty.js +0 -148
  39. package/lib/CSSPropertyOperations.js +0 -205
  40. package/lib/CallbackQueue.js +0 -106
  41. package/lib/ChangeEventPlugin.js +0 -325
  42. package/lib/DOMChildrenOperations.js +0 -194
  43. package/lib/DOMLazyTree.js +0 -118
  44. package/lib/DOMProperty.js +0 -206
  45. package/lib/DOMPropertyOperations.js +0 -221
  46. package/lib/Danger.js +0 -48
  47. package/lib/DefaultEventPluginOrder.js +0 -27
  48. package/lib/DisabledInputUtils.js +0 -50
  49. package/lib/EnterLeaveEventPlugin.js +0 -105
  50. package/lib/EventConstants.js +0 -97
  51. package/lib/EventPluginHub.js +0 -251
  52. package/lib/EventPluginRegistry.js +0 -247
  53. package/lib/EventPluginUtils.js +0 -229
  54. package/lib/EventPropagators.js +0 -137
  55. package/lib/FallbackCompositionState.js +0 -95
  56. package/lib/HTMLDOMPropertyConfig.js +0 -209
  57. package/lib/LinkedValueUtils.js +0 -136
  58. package/lib/NativeMethodsMixin.js +0 -167
  59. package/lib/ReactBrowserEventEmitter.js +0 -317
  60. package/lib/ReactChildReconciler.js +0 -154
  61. package/lib/ReactChildrenMutationWarningHook.js +0 -54
  62. package/lib/ReactComponentBrowserEnvironment.js +0 -30
  63. package/lib/ReactComponentEnvironment.js +0 -45
  64. package/lib/ReactComponentTreeTestUtils.js +0 -87
  65. package/lib/ReactCompositeComponent.js +0 -920
  66. package/lib/ReactDOM.js +0 -110
  67. package/lib/ReactDOMButton.js +0 -24
  68. package/lib/ReactDOMComponent.js +0 -1005
  69. package/lib/ReactDOMComponentTree.js +0 -188
  70. package/lib/ReactDOMContainerInfo.js +0 -33
  71. package/lib/ReactDOMEmptyComponent.js +0 -60
  72. package/lib/ReactDOMFiber.js +0 -78
  73. package/lib/ReactDOMIDOperations.js +0 -34
  74. package/lib/ReactDOMInput.js +0 -269
  75. package/lib/ReactDOMNullInputValuePropHook.js +0 -43
  76. package/lib/ReactDOMOption.js +0 -123
  77. package/lib/ReactDOMSelect.js +0 -201
  78. package/lib/ReactDOMSelection.js +0 -212
  79. package/lib/ReactDOMServer.js +0 -26
  80. package/lib/ReactDOMTextComponent.js +0 -164
  81. package/lib/ReactDOMTextarea.js +0 -155
  82. package/lib/ReactDOMTreeTraversal.js +0 -136
  83. package/lib/ReactDOMUnknownPropertyHook.js +0 -112
  84. package/lib/ReactDebugTool.js +0 -307
  85. package/lib/ReactDefaultBatchingStrategy.js +0 -68
  86. package/lib/ReactDefaultInjection.js +0 -84
  87. package/lib/ReactEmptyComponent.js +0 -30
  88. package/lib/ReactErrorUtils.js +0 -76
  89. package/lib/ReactEventEmitterMixin.js +0 -33
  90. package/lib/ReactEventListener.js +0 -157
  91. package/lib/ReactFeatureFlags.js +0 -22
  92. package/lib/ReactHostComponent.js +0 -76
  93. package/lib/ReactHostOperationHistoryHook.js +0 -37
  94. package/lib/ReactInjection.js +0 -36
  95. package/lib/ReactInputSelection.js +0 -124
  96. package/lib/ReactInstanceHandles.js +0 -302
  97. package/lib/ReactInstanceMap.js +0 -48
  98. package/lib/ReactInstrumentation.js +0 -21
  99. package/lib/ReactInvalidSetStateWarningHook.js +0 -36
  100. package/lib/ReactMarkupChecksum.js +0 -50
  101. package/lib/ReactMount.js +0 -495
  102. package/lib/ReactMultiChild.js +0 -451
  103. package/lib/ReactMultiChildUpdateTypes.js +0 -32
  104. package/lib/ReactNative.js +0 -71
  105. package/lib/ReactNativeAttributePayload.js +0 -371
  106. package/lib/ReactNativeBaseComponent.js +0 -198
  107. package/lib/ReactNativeBridgeEventPlugin.js +0 -60
  108. package/lib/ReactNativeComponentEnvironment.js +0 -31
  109. package/lib/ReactNativeComponentTree.js +0 -68
  110. package/lib/ReactNativeContainerInfo.js +0 -21
  111. package/lib/ReactNativeDOMIDOperations.js +0 -79
  112. package/lib/ReactNativeDefaultInjection.js +0 -101
  113. package/lib/ReactNativeEventEmitter.js +0 -191
  114. package/lib/ReactNativeEventPluginOrder.js +0 -16
  115. package/lib/ReactNativeGlobalResponderHandler.js +0 -25
  116. package/lib/ReactNativeMount.js +0 -193
  117. package/lib/ReactNativePropRegistry.js +0 -52
  118. package/lib/ReactNativeReconcileTransaction.js +0 -116
  119. package/lib/ReactNativeTagHandles.js +0 -56
  120. package/lib/ReactNativeTextComponent.js +0 -71
  121. package/lib/ReactNativeTreeTraversal.js +0 -127
  122. package/lib/ReactNodeTypes.js +0 -40
  123. package/lib/ReactNoop.js +0 -173
  124. package/lib/ReactOwner.js +0 -94
  125. package/lib/ReactPerf.js +0 -494
  126. package/lib/ReactReconcileTransaction.js +0 -178
  127. package/lib/ReactReconciler.js +0 -168
  128. package/lib/ReactRef.js +0 -80
  129. package/lib/ReactServerBatchingStrategy.js +0 -22
  130. package/lib/ReactServerRendering.js +0 -90
  131. package/lib/ReactServerRenderingTransaction.js +0 -90
  132. package/lib/ReactServerUpdateQueue.js +0 -141
  133. package/lib/ReactSimpleEmptyComponent.js +0 -37
  134. package/lib/ReactTestMount.js +0 -123
  135. package/lib/ReactTestReconcileTransaction.js +0 -108
  136. package/lib/ReactTestRenderer.js +0 -144
  137. package/lib/ReactTestUtils.js +0 -518
  138. package/lib/ReactUpdateQueue.js +0 -226
  139. package/lib/ReactUpdates.js +0 -251
  140. package/lib/ResponderEventPlugin.js +0 -510
  141. package/lib/ResponderSyntheticEvent.js +0 -39
  142. package/lib/ResponderTouchHistoryStore.js +0 -184
  143. package/lib/SVGDOMPropertyConfig.js +0 -302
  144. package/lib/SelectEventPlugin.js +0 -196
  145. package/lib/SimpleEventPlugin.js +0 -635
  146. package/lib/SyntheticAnimationEvent.js +0 -39
  147. package/lib/SyntheticClipboardEvent.js +0 -38
  148. package/lib/SyntheticCompositionEvent.js +0 -36
  149. package/lib/SyntheticDragEvent.js +0 -36
  150. package/lib/SyntheticEvent.js +0 -267
  151. package/lib/SyntheticFocusEvent.js +0 -36
  152. package/lib/SyntheticInputEvent.js +0 -37
  153. package/lib/SyntheticKeyboardEvent.js +0 -84
  154. package/lib/SyntheticMouseEvent.js +0 -72
  155. package/lib/SyntheticTouchEvent.js +0 -45
  156. package/lib/SyntheticTransitionEvent.js +0 -39
  157. package/lib/SyntheticUIEvent.js +0 -59
  158. package/lib/SyntheticWheelEvent.js +0 -54
  159. package/lib/TapEventPlugin.js +0 -110
  160. package/lib/TouchHistoryMath.js +0 -99
  161. package/lib/Transaction.js +0 -233
  162. package/lib/ViewportMetrics.js +0 -27
  163. package/lib/accumulate.js +0 -46
  164. package/lib/accumulateInto.js +0 -58
  165. package/lib/adler32.js +0 -44
  166. package/lib/createMicrosoftUnsafeLocalFunction.js +0 -32
  167. package/lib/createReactNativeComponentClass.js +0 -42
  168. package/lib/dangerousStyleValue.js +0 -79
  169. package/lib/escapeTextContentForBrowser.js +0 -122
  170. package/lib/findDOMNode.js +0 -60
  171. package/lib/findNodeHandle.js +0 -91
  172. package/lib/forEachAccumulated.js +0 -31
  173. package/lib/getEventCharCode.js +0 -50
  174. package/lib/getEventKey.js +0 -102
  175. package/lib/getEventModifierState.js +0 -43
  176. package/lib/getEventTarget.js +0 -35
  177. package/lib/getHostComponentFromComposite.js +0 -30
  178. package/lib/getNodeForCharacterOffset.js +0 -74
  179. package/lib/getTestDocument.js +0 -21
  180. package/lib/getTextContentAccessor.js +0 -33
  181. package/lib/getVendorPrefixedEventName.js +0 -101
  182. package/lib/instantiateReactComponent.js +0 -119
  183. package/lib/isEventSupported.js +0 -60
  184. package/lib/isTextInputElement.js +0 -51
  185. package/lib/quoteAttributeValueForBrowser.js +0 -26
  186. package/lib/reactComponentExpect.js +0 -217
  187. package/lib/setInnerHTML.js +0 -98
  188. package/lib/setTextContent.js +0 -48
  189. package/lib/shouldUpdateReactComponent.js +0 -42
  190. package/lib/validateDOMNesting.js +0 -369
@@ -1,108 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- * @providesModule ReactTestReconcileTransaction
10
- *
11
- */
12
- 'use strict';
13
-
14
- var _assign = require('object-assign');
15
-
16
- var CallbackQueue = require('./CallbackQueue');
17
- var PooledClass = require('./PooledClass');
18
- var Transaction = require('./Transaction');
19
- var ReactUpdateQueue = require('./ReactUpdateQueue');
20
-
21
- /**
22
- * Provides a `CallbackQueue` queue for collecting `onDOMReady` callbacks during
23
- * the performing of the transaction.
24
- */
25
- var ON_DOM_READY_QUEUEING = {
26
- /**
27
- * Initializes the internal `onDOMReady` queue.
28
- */
29
- initialize: function () {
30
- this.reactMountReady.reset();
31
- },
32
-
33
- /**
34
- * After DOM is flushed, invoke all registered `onDOMReady` callbacks.
35
- */
36
- close: function () {
37
- this.reactMountReady.notifyAll();
38
- }
39
- };
40
-
41
- /**
42
- * Executed within the scope of the `Transaction` instance. Consider these as
43
- * being member methods, but with an implied ordering while being isolated from
44
- * each other.
45
- */
46
- var TRANSACTION_WRAPPERS = [ON_DOM_READY_QUEUEING];
47
-
48
- /**
49
- * Currently:
50
- * - The order that these are listed in the transaction is critical:
51
- * - Suppresses events.
52
- * - Restores selection range.
53
- *
54
- * Future:
55
- * - Restore document/overflow scroll positions that were unintentionally
56
- * modified via DOM insertions above the top viewport boundary.
57
- * - Implement/integrate with customized constraint based layout system and keep
58
- * track of which dimensions must be remeasured.
59
- *
60
- * @class ReactTestReconcileTransaction
61
- */
62
- function ReactTestReconcileTransaction() {
63
- this.reinitializeTransaction();
64
- this.reactMountReady = CallbackQueue.getPooled(null);
65
- }
66
-
67
- var Mixin = {
68
- /**
69
- * @see Transaction
70
- * @abstract
71
- * @final
72
- * @return {array<object>} List of operation wrap procedures.
73
- * TODO: convert to array<TransactionWrapper>
74
- */
75
- getTransactionWrappers: function () {
76
- return TRANSACTION_WRAPPERS;
77
- },
78
-
79
- /**
80
- * @return {object} The queue to collect `onDOMReady` callbacks with.
81
- * TODO: convert to ReactMountReady
82
- */
83
- getReactMountReady: function () {
84
- return this.reactMountReady;
85
- },
86
-
87
- /**
88
- * @return {object} The queue to collect React async events.
89
- */
90
- getUpdateQueue: function () {
91
- return ReactUpdateQueue;
92
- },
93
-
94
- /**
95
- * `PooledClass` looks for this, and will invoke this before allowing this
96
- * instance to be reused.
97
- */
98
- destructor: function () {
99
- CallbackQueue.release(this.reactMountReady);
100
- this.reactMountReady = null;
101
- }
102
- };
103
-
104
- _assign(ReactTestReconcileTransaction.prototype, Transaction.Mixin, ReactTestReconcileTransaction, Mixin);
105
-
106
- PooledClass.addPoolingTo(ReactTestReconcileTransaction);
107
-
108
- module.exports = ReactTestReconcileTransaction;
@@ -1,144 +0,0 @@
1
- /**
2
- * Copyright 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- * @providesModule ReactTestRenderer
10
- */
11
-
12
- 'use strict';
13
-
14
- var _assign = require('object-assign');
15
-
16
- function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
17
-
18
- var ReactComponentEnvironment = require('./ReactComponentEnvironment');
19
- var ReactDefaultBatchingStrategy = require('./ReactDefaultBatchingStrategy');
20
- var ReactEmptyComponent = require('./ReactEmptyComponent');
21
- var ReactMultiChild = require('./ReactMultiChild');
22
- var ReactHostComponent = require('./ReactHostComponent');
23
- var ReactTestMount = require('./ReactTestMount');
24
- var ReactTestReconcileTransaction = require('./ReactTestReconcileTransaction');
25
- var ReactUpdates = require('./ReactUpdates');
26
-
27
- var renderSubtreeIntoContainer = require('./renderSubtreeIntoContainer');
28
-
29
- /**
30
- * Drill down (through composites and empty components) until we get a native or
31
- * native text component.
32
- *
33
- * This is pretty polymorphic but unavoidable with the current structure we have
34
- * for `_renderedChildren`.
35
- */
36
- function getRenderedHostOrTextFromComponent(component) {
37
- var rendered;
38
- while (rendered = component._renderedComponent) {
39
- component = rendered;
40
- }
41
- return component;
42
- }
43
-
44
- // =============================================================================
45
-
46
- var ReactTestComponent = function (element) {
47
- this._currentElement = element;
48
- this._renderedChildren = null;
49
- this._topLevelWrapper = null;
50
- };
51
- ReactTestComponent.prototype.mountComponent = function (transaction, nativeParent, nativeContainerInfo, context) {
52
- var element = this._currentElement;
53
- this.mountChildren(element.props.children, transaction, context);
54
- };
55
- ReactTestComponent.prototype.receiveComponent = function (nextElement, transaction, context) {
56
- this._currentElement = nextElement;
57
- this.updateChildren(nextElement.props.children, transaction, context);
58
- };
59
- ReactTestComponent.prototype.getHostNode = function () {};
60
- ReactTestComponent.prototype.getPublicInstance = function () {
61
- // I can't say this makes a ton of sense but it seems better than throwing.
62
- // Maybe we'll revise later if someone has a good use case.
63
- return null;
64
- };
65
- ReactTestComponent.prototype.unmountComponent = function () {};
66
- ReactTestComponent.prototype.toJSON = function () {
67
- var _currentElement$props = this._currentElement.props;
68
- var children = _currentElement$props.children;
69
-
70
- var props = _objectWithoutProperties(_currentElement$props, ['children']);
71
-
72
- var childrenJSON = [];
73
- for (var key in this._renderedChildren) {
74
- var inst = this._renderedChildren[key];
75
- inst = getRenderedHostOrTextFromComponent(inst);
76
- var json = inst.toJSON();
77
- if (json !== undefined) {
78
- childrenJSON.push(json);
79
- }
80
- }
81
- var object = {
82
- type: this._currentElement.type,
83
- props: props,
84
- children: childrenJSON.length ? childrenJSON : null
85
- };
86
- Object.defineProperty(object, '$$typeof', {
87
- value: Symbol['for']('react.test.json')
88
- });
89
- return object;
90
- };
91
- _assign(ReactTestComponent.prototype, ReactMultiChild.Mixin);
92
-
93
- // =============================================================================
94
-
95
- var ReactTestTextComponent = function (element) {
96
- this._currentElement = element;
97
- };
98
- ReactTestTextComponent.prototype.mountComponent = function () {};
99
- ReactTestTextComponent.prototype.receiveComponent = function (nextElement) {
100
- this._currentElement = nextElement;
101
- };
102
- ReactTestTextComponent.prototype.getHostNode = function () {};
103
- ReactTestTextComponent.prototype.unmountComponent = function () {};
104
- ReactTestTextComponent.prototype.toJSON = function () {
105
- return this._currentElement;
106
- };
107
-
108
- // =============================================================================
109
-
110
- var ReactTestEmptyComponent = function (element) {
111
- this._currentElement = null;
112
- };
113
- ReactTestEmptyComponent.prototype.mountComponent = function () {};
114
- ReactTestEmptyComponent.prototype.receiveComponent = function () {};
115
- ReactTestEmptyComponent.prototype.getHostNode = function () {};
116
- ReactTestEmptyComponent.prototype.unmountComponent = function () {};
117
- ReactTestEmptyComponent.prototype.toJSON = function () {};
118
-
119
- // =============================================================================
120
-
121
- ReactUpdates.injection.injectReconcileTransaction(ReactTestReconcileTransaction);
122
- ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);
123
-
124
- ReactHostComponent.injection.injectGenericComponentClass(ReactTestComponent);
125
- ReactHostComponent.injection.injectTextComponentClass(ReactTestTextComponent);
126
- ReactEmptyComponent.injection.injectEmptyComponentFactory(function () {
127
- return new ReactTestEmptyComponent();
128
- });
129
-
130
- ReactComponentEnvironment.injection.injectEnvironment({
131
- processChildrenUpdates: function () {},
132
- replaceNodeWithMarkup: function () {}
133
- });
134
-
135
- var ReactTestRenderer = {
136
- create: ReactTestMount.render,
137
-
138
- /* eslint-disable camelcase */
139
- unstable_batchedUpdates: ReactUpdates.batchedUpdates,
140
- unstable_renderSubtreeIntoContainer: renderSubtreeIntoContainer
141
- };
142
-
143
- /* eslint-enable camelcase */
144
- module.exports = ReactTestRenderer;
@@ -1,518 +0,0 @@
1
- /**
2
- * Copyright 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- * @providesModule ReactTestUtils
10
- */
11
-
12
- 'use strict';
13
-
14
- var _prodInvariant = require('./reactProdInvariant'),
15
- _assign = require('object-assign');
16
-
17
- var EventConstants = require('./EventConstants');
18
- var EventPluginHub = require('./EventPluginHub');
19
- var EventPluginRegistry = require('./EventPluginRegistry');
20
- var EventPropagators = require('./EventPropagators');
21
- var React = require('./React');
22
- var ReactDefaultInjection = require('./ReactDefaultInjection');
23
- var ReactDOM = require('./ReactDOM');
24
- var ReactDOMComponentTree = require('./ReactDOMComponentTree');
25
- var ReactElement = require('./ReactElement');
26
- var ReactBrowserEventEmitter = require('./ReactBrowserEventEmitter');
27
- var ReactCompositeComponent = require('./ReactCompositeComponent');
28
- var ReactInstanceMap = require('./ReactInstanceMap');
29
- var ReactReconciler = require('./ReactReconciler');
30
- var ReactUpdates = require('./ReactUpdates');
31
- var SyntheticEvent = require('./SyntheticEvent');
32
-
33
- var emptyObject = require('fbjs/lib/emptyObject');
34
- var findDOMNode = require('./findDOMNode');
35
- var invariant = require('fbjs/lib/invariant');
36
-
37
- var topLevelTypes = EventConstants.topLevelTypes;
38
-
39
- function Event(suffix) {}
40
-
41
- /**
42
- * @class ReactTestUtils
43
- */
44
-
45
- function findAllInRenderedTreeInternal(inst, test) {
46
- if (!inst || !inst.getPublicInstance) {
47
- return [];
48
- }
49
- var publicInst = inst.getPublicInstance();
50
- var ret = test(publicInst) ? [publicInst] : [];
51
- var currentElement = inst._currentElement;
52
- if (ReactTestUtils.isDOMComponent(publicInst)) {
53
- var renderedChildren = inst._renderedChildren;
54
- var key;
55
- for (key in renderedChildren) {
56
- if (!renderedChildren.hasOwnProperty(key)) {
57
- continue;
58
- }
59
- ret = ret.concat(findAllInRenderedTreeInternal(renderedChildren[key], test));
60
- }
61
- } else if (ReactElement.isValidElement(currentElement) && typeof currentElement.type === 'function') {
62
- ret = ret.concat(findAllInRenderedTreeInternal(inst._renderedComponent, test));
63
- }
64
- return ret;
65
- }
66
-
67
- /**
68
- * Utilities for making it easy to test React components.
69
- *
70
- * See https://facebook.github.io/react/docs/test-utils.html
71
- *
72
- * Todo: Support the entire DOM.scry query syntax. For now, these simple
73
- * utilities will suffice for testing purposes.
74
- * @lends ReactTestUtils
75
- */
76
- var ReactTestUtils = {
77
- renderIntoDocument: function (instance) {
78
- var div = document.createElement('div');
79
- // None of our tests actually require attaching the container to the
80
- // DOM, and doing so creates a mess that we rely on test isolation to
81
- // clean up, so we're going to stop honoring the name of this method
82
- // (and probably rename it eventually) if no problems arise.
83
- // document.documentElement.appendChild(div);
84
- return ReactDOM.render(instance, div);
85
- },
86
-
87
- isElement: function (element) {
88
- return ReactElement.isValidElement(element);
89
- },
90
-
91
- isElementOfType: function (inst, convenienceConstructor) {
92
- return ReactElement.isValidElement(inst) && inst.type === convenienceConstructor;
93
- },
94
-
95
- isDOMComponent: function (inst) {
96
- return !!(inst && inst.nodeType === 1 && inst.tagName);
97
- },
98
-
99
- isDOMComponentElement: function (inst) {
100
- return !!(inst && ReactElement.isValidElement(inst) && !!inst.tagName);
101
- },
102
-
103
- isCompositeComponent: function (inst) {
104
- if (ReactTestUtils.isDOMComponent(inst)) {
105
- // Accessing inst.setState warns; just return false as that'll be what
106
- // this returns when we have DOM nodes as refs directly
107
- return false;
108
- }
109
- return inst != null && typeof inst.render === 'function' && typeof inst.setState === 'function';
110
- },
111
-
112
- isCompositeComponentWithType: function (inst, type) {
113
- if (!ReactTestUtils.isCompositeComponent(inst)) {
114
- return false;
115
- }
116
- var internalInstance = ReactInstanceMap.get(inst);
117
- var constructor = internalInstance._currentElement.type;
118
-
119
- return constructor === type;
120
- },
121
-
122
- isCompositeComponentElement: function (inst) {
123
- if (!ReactElement.isValidElement(inst)) {
124
- return false;
125
- }
126
- // We check the prototype of the type that will get mounted, not the
127
- // instance itself. This is a future proof way of duck typing.
128
- var prototype = inst.type.prototype;
129
- return typeof prototype.render === 'function' && typeof prototype.setState === 'function';
130
- },
131
-
132
- isCompositeComponentElementWithType: function (inst, type) {
133
- var internalInstance = ReactInstanceMap.get(inst);
134
- var constructor = internalInstance._currentElement.type;
135
-
136
- return !!(ReactTestUtils.isCompositeComponentElement(inst) && constructor === type);
137
- },
138
-
139
- getRenderedChildOfCompositeComponent: function (inst) {
140
- if (!ReactTestUtils.isCompositeComponent(inst)) {
141
- return null;
142
- }
143
- var internalInstance = ReactInstanceMap.get(inst);
144
- return internalInstance._renderedComponent.getPublicInstance();
145
- },
146
-
147
- findAllInRenderedTree: function (inst, test) {
148
- if (!inst) {
149
- return [];
150
- }
151
- !ReactTestUtils.isCompositeComponent(inst) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'findAllInRenderedTree(...): instance must be a composite component') : _prodInvariant('10') : void 0;
152
- return findAllInRenderedTreeInternal(ReactInstanceMap.get(inst), test);
153
- },
154
-
155
- /**
156
- * Finds all instance of components in the rendered tree that are DOM
157
- * components with the class name matching `className`.
158
- * @return {array} an array of all the matches.
159
- */
160
- scryRenderedDOMComponentsWithClass: function (root, classNames) {
161
- return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
162
- if (ReactTestUtils.isDOMComponent(inst)) {
163
- var className = inst.className;
164
- if (typeof className !== 'string') {
165
- // SVG, probably.
166
- className = inst.getAttribute('class') || '';
167
- }
168
- var classList = className.split(/\s+/);
169
-
170
- if (!Array.isArray(classNames)) {
171
- !(classNames !== undefined) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'TestUtils.scryRenderedDOMComponentsWithClass expects a className as a second argument.') : _prodInvariant('11') : void 0;
172
- classNames = classNames.split(/\s+/);
173
- }
174
- return classNames.every(function (name) {
175
- return classList.indexOf(name) !== -1;
176
- });
177
- }
178
- return false;
179
- });
180
- },
181
-
182
- /**
183
- * Like scryRenderedDOMComponentsWithClass but expects there to be one result,
184
- * and returns that one result, or throws exception if there is any other
185
- * number of matches besides one.
186
- * @return {!ReactDOMComponent} The one match.
187
- */
188
- findRenderedDOMComponentWithClass: function (root, className) {
189
- var all = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
190
- if (all.length !== 1) {
191
- throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for class:' + className);
192
- }
193
- return all[0];
194
- },
195
-
196
- /**
197
- * Finds all instance of components in the rendered tree that are DOM
198
- * components with the tag name matching `tagName`.
199
- * @return {array} an array of all the matches.
200
- */
201
- scryRenderedDOMComponentsWithTag: function (root, tagName) {
202
- return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
203
- return ReactTestUtils.isDOMComponent(inst) && inst.tagName.toUpperCase() === tagName.toUpperCase();
204
- });
205
- },
206
-
207
- /**
208
- * Like scryRenderedDOMComponentsWithTag but expects there to be one result,
209
- * and returns that one result, or throws exception if there is any other
210
- * number of matches besides one.
211
- * @return {!ReactDOMComponent} The one match.
212
- */
213
- findRenderedDOMComponentWithTag: function (root, tagName) {
214
- var all = ReactTestUtils.scryRenderedDOMComponentsWithTag(root, tagName);
215
- if (all.length !== 1) {
216
- throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for tag:' + tagName);
217
- }
218
- return all[0];
219
- },
220
-
221
- /**
222
- * Finds all instances of components with type equal to `componentType`.
223
- * @return {array} an array of all the matches.
224
- */
225
- scryRenderedComponentsWithType: function (root, componentType) {
226
- return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
227
- return ReactTestUtils.isCompositeComponentWithType(inst, componentType);
228
- });
229
- },
230
-
231
- /**
232
- * Same as `scryRenderedComponentsWithType` but expects there to be one result
233
- * and returns that one result, or throws exception if there is any other
234
- * number of matches besides one.
235
- * @return {!ReactComponent} The one match.
236
- */
237
- findRenderedComponentWithType: function (root, componentType) {
238
- var all = ReactTestUtils.scryRenderedComponentsWithType(root, componentType);
239
- if (all.length !== 1) {
240
- throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for componentType:' + componentType);
241
- }
242
- return all[0];
243
- },
244
-
245
- /**
246
- * Pass a mocked component module to this method to augment it with
247
- * useful methods that allow it to be used as a dummy React component.
248
- * Instead of rendering as usual, the component will become a simple
249
- * <div> containing any provided children.
250
- *
251
- * @param {object} module the mock function object exported from a
252
- * module that defines the component to be mocked
253
- * @param {?string} mockTagName optional dummy root tag name to return
254
- * from render method (overrides
255
- * module.mockTagName if provided)
256
- * @return {object} the ReactTestUtils object (for chaining)
257
- */
258
- mockComponent: function (module, mockTagName) {
259
- mockTagName = mockTagName || module.mockTagName || 'div';
260
-
261
- module.prototype.render.mockImplementation(function () {
262
- return React.createElement(mockTagName, null, this.props.children);
263
- });
264
-
265
- return this;
266
- },
267
-
268
- /**
269
- * Simulates a top level event being dispatched from a raw event that occurred
270
- * on an `Element` node.
271
- * @param {Object} topLevelType A type from `EventConstants.topLevelTypes`
272
- * @param {!Element} node The dom to simulate an event occurring on.
273
- * @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
274
- */
275
- simulateNativeEventOnNode: function (topLevelType, node, fakeNativeEvent) {
276
- fakeNativeEvent.target = node;
277
- ReactBrowserEventEmitter.ReactEventListener.dispatchEvent(topLevelType, fakeNativeEvent);
278
- },
279
-
280
- /**
281
- * Simulates a top level event being dispatched from a raw event that occurred
282
- * on the `ReactDOMComponent` `comp`.
283
- * @param {Object} topLevelType A type from `EventConstants.topLevelTypes`.
284
- * @param {!ReactDOMComponent} comp
285
- * @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
286
- */
287
- simulateNativeEventOnDOMComponent: function (topLevelType, comp, fakeNativeEvent) {
288
- ReactTestUtils.simulateNativeEventOnNode(topLevelType, findDOMNode(comp), fakeNativeEvent);
289
- },
290
-
291
- nativeTouchData: function (x, y) {
292
- return {
293
- touches: [{ pageX: x, pageY: y }]
294
- };
295
- },
296
-
297
- createRenderer: function () {
298
- return new ReactShallowRenderer();
299
- },
300
-
301
- Simulate: null,
302
- SimulateNative: {}
303
- };
304
-
305
- /**
306
- * @class ReactShallowRenderer
307
- */
308
- var ReactShallowRenderer = function () {
309
- this._instance = null;
310
- };
311
-
312
- ReactShallowRenderer.prototype.getMountedInstance = function () {
313
- return this._instance ? this._instance._instance : null;
314
- };
315
-
316
- var nextDebugID = 1;
317
-
318
- var NoopInternalComponent = function (element) {
319
- this._renderedOutput = element;
320
- this._currentElement = element;
321
-
322
- if (process.env.NODE_ENV !== 'production') {
323
- this._debugID = nextDebugID++;
324
- }
325
- };
326
-
327
- NoopInternalComponent.prototype = {
328
-
329
- mountComponent: function () {},
330
-
331
- receiveComponent: function (element) {
332
- this._renderedOutput = element;
333
- this._currentElement = element;
334
- },
335
-
336
- getHostNode: function () {
337
- return undefined;
338
- },
339
-
340
- unmountComponent: function () {},
341
-
342
- getPublicInstance: function () {
343
- return null;
344
- }
345
- };
346
-
347
- var ShallowComponentWrapper = function (element) {
348
- // TODO: Consolidate with instantiateReactComponent
349
- if (process.env.NODE_ENV !== 'production') {
350
- this._debugID = nextDebugID++;
351
- }
352
-
353
- this.construct(element);
354
- };
355
- _assign(ShallowComponentWrapper.prototype, ReactCompositeComponent.Mixin, {
356
- _constructComponent: ReactCompositeComponent.Mixin._constructComponentWithoutOwner,
357
- _instantiateReactComponent: function (element) {
358
- return new NoopInternalComponent(element);
359
- },
360
- _replaceNodeWithMarkup: function () {},
361
- _renderValidatedComponent: ReactCompositeComponent.Mixin._renderValidatedComponentWithoutOwnerOrContext
362
- });
363
-
364
- ReactShallowRenderer.prototype.render = function (element, context) {
365
- // Ensure we've done the default injections. This might not be true in the
366
- // case of a simple test that only requires React and the TestUtils in
367
- // conjunction with an inline-requires transform.
368
- ReactDefaultInjection.inject();
369
-
370
- !ReactElement.isValidElement(element) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactShallowRenderer render(): Invalid component element.%s', typeof element === 'function' ? ' Instead of passing a component class, make sure to instantiate ' + 'it by passing it to React.createElement.' : '') : _prodInvariant('12', typeof element === 'function' ? ' Instead of passing a component class, make sure to instantiate ' + 'it by passing it to React.createElement.' : '') : void 0;
371
- !(typeof element.type !== 'string') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactShallowRenderer render(): Shallow rendering works only with custom components, not primitives (%s). Instead of calling `.render(el)` and inspecting the rendered output, look at `el.props` directly instead.', element.type) : _prodInvariant('13', element.type) : void 0;
372
-
373
- if (!context) {
374
- context = emptyObject;
375
- }
376
- ReactUpdates.batchedUpdates(_batchedRender, this, element, context);
377
-
378
- return this.getRenderOutput();
379
- };
380
-
381
- function _batchedRender(renderer, element, context) {
382
- var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(true);
383
- renderer._render(element, transaction, context);
384
- ReactUpdates.ReactReconcileTransaction.release(transaction);
385
- }
386
-
387
- ReactShallowRenderer.prototype.getRenderOutput = function () {
388
- return this._instance && this._instance._renderedComponent && this._instance._renderedComponent._renderedOutput || null;
389
- };
390
-
391
- ReactShallowRenderer.prototype.unmount = function () {
392
- if (this._instance) {
393
- ReactReconciler.unmountComponent(this._instance, false);
394
- }
395
- };
396
-
397
- ReactShallowRenderer.prototype._render = function (element, transaction, context) {
398
- if (this._instance) {
399
- ReactReconciler.receiveComponent(this._instance, element, transaction, context);
400
- } else {
401
- var instance = new ShallowComponentWrapper(element);
402
- ReactReconciler.mountComponent(instance, transaction, null, null, context, 0);
403
- this._instance = instance;
404
- }
405
- };
406
-
407
- /**
408
- * Exports:
409
- *
410
- * - `ReactTestUtils.Simulate.click(Element/ReactDOMComponent)`
411
- * - `ReactTestUtils.Simulate.mouseMove(Element/ReactDOMComponent)`
412
- * - `ReactTestUtils.Simulate.change(Element/ReactDOMComponent)`
413
- * - ... (All keys from event plugin `eventTypes` objects)
414
- */
415
- function makeSimulator(eventType) {
416
- return function (domComponentOrNode, eventData) {
417
- var node;
418
- !!React.isValidElement(domComponentOrNode) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'TestUtils.Simulate expects a component instance and not a ReactElement.TestUtils.Simulate will not work if you are using shallow rendering.') : _prodInvariant('14') : void 0;
419
- if (ReactTestUtils.isDOMComponent(domComponentOrNode)) {
420
- node = findDOMNode(domComponentOrNode);
421
- } else if (domComponentOrNode.tagName) {
422
- node = domComponentOrNode;
423
- }
424
-
425
- var dispatchConfig = EventPluginRegistry.eventNameDispatchConfigs[eventType];
426
-
427
- var fakeNativeEvent = new Event();
428
- fakeNativeEvent.target = node;
429
- fakeNativeEvent.type = eventType.toLowerCase();
430
-
431
- // We don't use SyntheticEvent.getPooled in order to not have to worry about
432
- // properly destroying any properties assigned from `eventData` upon release
433
- var event = new SyntheticEvent(dispatchConfig, ReactDOMComponentTree.getInstanceFromNode(node), fakeNativeEvent, node);
434
- // Since we aren't using pooling, always persist the event. This will make
435
- // sure it's marked and won't warn when setting additional properties.
436
- event.persist();
437
- _assign(event, eventData);
438
-
439
- if (dispatchConfig.phasedRegistrationNames) {
440
- EventPropagators.accumulateTwoPhaseDispatches(event);
441
- } else {
442
- EventPropagators.accumulateDirectDispatches(event);
443
- }
444
-
445
- ReactUpdates.batchedUpdates(function () {
446
- EventPluginHub.enqueueEvents(event);
447
- EventPluginHub.processEventQueue(true);
448
- });
449
- };
450
- }
451
-
452
- function buildSimulators() {
453
- ReactTestUtils.Simulate = {};
454
-
455
- var eventType;
456
- for (eventType in EventPluginRegistry.eventNameDispatchConfigs) {
457
- /**
458
- * @param {!Element|ReactDOMComponent} domComponentOrNode
459
- * @param {?object} eventData Fake event data to use in SyntheticEvent.
460
- */
461
- ReactTestUtils.Simulate[eventType] = makeSimulator(eventType);
462
- }
463
- }
464
-
465
- // Rebuild ReactTestUtils.Simulate whenever event plugins are injected
466
- var oldInjectEventPluginOrder = EventPluginHub.injection.injectEventPluginOrder;
467
- EventPluginHub.injection.injectEventPluginOrder = function () {
468
- oldInjectEventPluginOrder.apply(this, arguments);
469
- buildSimulators();
470
- };
471
- var oldInjectEventPlugins = EventPluginHub.injection.injectEventPluginsByName;
472
- EventPluginHub.injection.injectEventPluginsByName = function () {
473
- oldInjectEventPlugins.apply(this, arguments);
474
- buildSimulators();
475
- };
476
-
477
- buildSimulators();
478
-
479
- /**
480
- * Exports:
481
- *
482
- * - `ReactTestUtils.SimulateNative.click(Element/ReactDOMComponent)`
483
- * - `ReactTestUtils.SimulateNative.mouseMove(Element/ReactDOMComponent)`
484
- * - `ReactTestUtils.SimulateNative.mouseIn/ReactDOMComponent)`
485
- * - `ReactTestUtils.SimulateNative.mouseOut(Element/ReactDOMComponent)`
486
- * - ... (All keys from `EventConstants.topLevelTypes`)
487
- *
488
- * Note: Top level event types are a subset of the entire set of handler types
489
- * (which include a broader set of "synthetic" events). For example, onDragDone
490
- * is a synthetic event. Except when testing an event plugin or React's event
491
- * handling code specifically, you probably want to use ReactTestUtils.Simulate
492
- * to dispatch synthetic events.
493
- */
494
-
495
- function makeNativeSimulator(eventType) {
496
- return function (domComponentOrNode, nativeEventData) {
497
- var fakeNativeEvent = new Event(eventType);
498
- _assign(fakeNativeEvent, nativeEventData);
499
- if (ReactTestUtils.isDOMComponent(domComponentOrNode)) {
500
- ReactTestUtils.simulateNativeEventOnDOMComponent(eventType, domComponentOrNode, fakeNativeEvent);
501
- } else if (domComponentOrNode.tagName) {
502
- // Will allow on actual dom nodes.
503
- ReactTestUtils.simulateNativeEventOnNode(eventType, domComponentOrNode, fakeNativeEvent);
504
- }
505
- };
506
- }
507
-
508
- Object.keys(topLevelTypes).forEach(function (eventType) {
509
- // Event type is stored as 'topClick' - we transform that to 'click'
510
- var convenienceName = eventType.indexOf('top') === 0 ? eventType.charAt(3).toLowerCase() + eventType.substr(4) : eventType;
511
- /**
512
- * @param {!Element|ReactDOMComponent} domComponentOrNode
513
- * @param {?Event} nativeEventData Fake native event to use in SyntheticEvent.
514
- */
515
- ReactTestUtils.SimulateNative[convenienceName] = makeNativeSimulator(eventType);
516
- });
517
-
518
- module.exports = ReactTestUtils;