react 15.3.2 → 15.4.0-rc.4

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 (210) hide show
  1. package/dist/react-with-addons.js +3864 -21390
  2. package/dist/react-with-addons.min.js +3 -6
  3. package/dist/react.js +2639 -19486
  4. package/dist/react.min.js +2 -6
  5. package/lib/KeyEscapeUtils.js +0 -1
  6. package/lib/LinkedStateMixin.js +1 -3
  7. package/lib/PooledClass.js +3 -1
  8. package/lib/React.js +0 -1
  9. package/lib/ReactAddonsDOMDependencies.js +35 -0
  10. package/lib/ReactAddonsDOMDependenciesUMDShim.js +31 -0
  11. package/lib/ReactCSSTransitionGroup.js +60 -43
  12. package/lib/ReactCSSTransitionGroupChild.js +2 -3
  13. package/lib/ReactChildren.js +0 -1
  14. package/lib/ReactClass.js +38 -54
  15. package/lib/ReactComponent.js +0 -1
  16. package/lib/ReactComponentTreeDevtool.js +0 -1
  17. package/lib/ReactComponentTreeHook.js +84 -101
  18. package/lib/{DOMNamespaces.js → ReactComponentTreeHookUMDShim.js} +4 -7
  19. package/lib/ReactComponentWithPureRenderMixin.js +0 -1
  20. package/lib/ReactCurrentOwner.js +1 -2
  21. package/lib/{renderSubtreeIntoContainer.js → ReactCurrentOwnerUMDShim.js} +5 -4
  22. package/lib/ReactDOMFactories.js +0 -1
  23. package/lib/ReactElement.js +6 -14
  24. package/lib/ReactElementSymbol.js +19 -0
  25. package/lib/{ReactDOMComponentFlags.js → ReactElementType.js} +3 -9
  26. package/lib/ReactElementValidator.js +1 -3
  27. package/lib/ReactFragment.js +0 -1
  28. package/lib/ReactLink.js +0 -1
  29. package/lib/ReactNoopUpdateQueue.js +0 -1
  30. package/lib/ReactPropTypeLocationNames.js +1 -1
  31. package/lib/ReactPropTypeLocations.js +2 -12
  32. package/lib/ReactPropTypes.js +5 -3
  33. package/lib/ReactPropTypesSecret.js +1 -1
  34. package/lib/ReactPureComponent.js +0 -1
  35. package/lib/ReactStateSetters.js +0 -1
  36. package/lib/ReactTransitionChildMapping.js +0 -1
  37. package/lib/ReactTransitionEvents.js +1 -2
  38. package/lib/ReactTransitionGroup.js +145 -142
  39. package/lib/ReactUMDEntry.js +11 -6
  40. package/lib/{ReactDOMFeatureFlags.js → ReactUMDShim.js} +3 -6
  41. package/lib/ReactVersion.js +1 -2
  42. package/lib/ReactWithAddons.js +15 -3
  43. package/lib/ReactWithAddonsUMDEntry.js +11 -6
  44. package/lib/canDefineProperty.js +2 -1
  45. package/lib/checkReactTypeSpec.js +0 -1
  46. package/lib/deprecated.js +0 -1
  47. package/lib/flattenChildren.js +0 -1
  48. package/lib/getIteratorFn.js +0 -1
  49. package/lib/onlyChild.js +0 -1
  50. package/lib/reactProdInvariant.js +0 -1
  51. package/lib/shallowCompare.js +1 -2
  52. package/lib/sliceChildren.js +0 -1
  53. package/lib/traverseAllChildren.js +11 -3
  54. package/lib/update.js +6 -8
  55. package/package.json +1 -1
  56. package/lib/AutoFocusUtils.js +0 -24
  57. package/lib/BeforeInputEventPlugin.js +0 -390
  58. package/lib/CSSProperty.js +0 -148
  59. package/lib/CSSPropertyOperations.js +0 -205
  60. package/lib/CallbackQueue.js +0 -106
  61. package/lib/ChangeEventPlugin.js +0 -325
  62. package/lib/DOMChildrenOperations.js +0 -194
  63. package/lib/DOMLazyTree.js +0 -118
  64. package/lib/DOMProperty.js +0 -206
  65. package/lib/DOMPropertyOperations.js +0 -221
  66. package/lib/Danger.js +0 -48
  67. package/lib/DefaultEventPluginOrder.js +0 -27
  68. package/lib/DisabledInputUtils.js +0 -50
  69. package/lib/EnterLeaveEventPlugin.js +0 -105
  70. package/lib/EventConstants.js +0 -97
  71. package/lib/EventPluginHub.js +0 -251
  72. package/lib/EventPluginRegistry.js +0 -247
  73. package/lib/EventPluginUtils.js +0 -229
  74. package/lib/EventPropagators.js +0 -137
  75. package/lib/FallbackCompositionState.js +0 -95
  76. package/lib/HTMLDOMPropertyConfig.js +0 -212
  77. package/lib/LinkedValueUtils.js +0 -136
  78. package/lib/NativeMethodsMixin.js +0 -167
  79. package/lib/ReactBrowserEventEmitter.js +0 -330
  80. package/lib/ReactChildReconciler.js +0 -154
  81. package/lib/ReactChildrenMutationWarningHook.js +0 -54
  82. package/lib/ReactComponentBrowserEnvironment.js +0 -30
  83. package/lib/ReactComponentEnvironment.js +0 -45
  84. package/lib/ReactComponentTreeTestUtils.js +0 -87
  85. package/lib/ReactCompositeComponent.js +0 -904
  86. package/lib/ReactDOM.js +0 -110
  87. package/lib/ReactDOMButton.js +0 -24
  88. package/lib/ReactDOMComponent.js +0 -1006
  89. package/lib/ReactDOMComponentTree.js +0 -188
  90. package/lib/ReactDOMContainerInfo.js +0 -33
  91. package/lib/ReactDOMEmptyComponent.js +0 -60
  92. package/lib/ReactDOMFiber.js +0 -76
  93. package/lib/ReactDOMIDOperations.js +0 -34
  94. package/lib/ReactDOMInput.js +0 -269
  95. package/lib/ReactDOMNullInputValuePropHook.js +0 -43
  96. package/lib/ReactDOMOption.js +0 -123
  97. package/lib/ReactDOMSelect.js +0 -201
  98. package/lib/ReactDOMSelection.js +0 -212
  99. package/lib/ReactDOMServer.js +0 -26
  100. package/lib/ReactDOMTextComponent.js +0 -164
  101. package/lib/ReactDOMTextarea.js +0 -155
  102. package/lib/ReactDOMTreeTraversal.js +0 -136
  103. package/lib/ReactDOMUnknownPropertyHook.js +0 -112
  104. package/lib/ReactDebugTool.js +0 -301
  105. package/lib/ReactDefaultBatchingStrategy.js +0 -68
  106. package/lib/ReactDefaultInjection.js +0 -84
  107. package/lib/ReactEmptyComponent.js +0 -30
  108. package/lib/ReactErrorUtils.js +0 -76
  109. package/lib/ReactEventEmitterMixin.js +0 -33
  110. package/lib/ReactEventListener.js +0 -157
  111. package/lib/ReactFeatureFlags.js +0 -22
  112. package/lib/ReactHostComponent.js +0 -76
  113. package/lib/ReactHostOperationHistoryHook.js +0 -37
  114. package/lib/ReactInjection.js +0 -36
  115. package/lib/ReactInputSelection.js +0 -124
  116. package/lib/ReactInstanceHandles.js +0 -302
  117. package/lib/ReactInstanceMap.js +0 -48
  118. package/lib/ReactInstrumentation.js +0 -21
  119. package/lib/ReactInvalidSetStateWarningHook.js +0 -36
  120. package/lib/ReactMarkupChecksum.js +0 -50
  121. package/lib/ReactMount.js +0 -534
  122. package/lib/ReactMultiChild.js +0 -451
  123. package/lib/ReactMultiChildUpdateTypes.js +0 -32
  124. package/lib/ReactNative.js +0 -71
  125. package/lib/ReactNativeAttributePayload.js +0 -371
  126. package/lib/ReactNativeBaseComponent.js +0 -198
  127. package/lib/ReactNativeBridgeEventPlugin.js +0 -60
  128. package/lib/ReactNativeComponentEnvironment.js +0 -31
  129. package/lib/ReactNativeComponentTree.js +0 -68
  130. package/lib/ReactNativeContainerInfo.js +0 -21
  131. package/lib/ReactNativeDOMIDOperations.js +0 -79
  132. package/lib/ReactNativeDefaultInjection.js +0 -101
  133. package/lib/ReactNativeEventEmitter.js +0 -191
  134. package/lib/ReactNativeEventPluginOrder.js +0 -16
  135. package/lib/ReactNativeGlobalResponderHandler.js +0 -25
  136. package/lib/ReactNativeMount.js +0 -193
  137. package/lib/ReactNativePropRegistry.js +0 -52
  138. package/lib/ReactNativeReconcileTransaction.js +0 -129
  139. package/lib/ReactNativeTagHandles.js +0 -56
  140. package/lib/ReactNativeTextComponent.js +0 -71
  141. package/lib/ReactNativeTreeTraversal.js +0 -127
  142. package/lib/ReactNodeTypes.js +0 -40
  143. package/lib/ReactNoop.js +0 -173
  144. package/lib/ReactOwner.js +0 -94
  145. package/lib/ReactPerf.js +0 -494
  146. package/lib/ReactReconcileTransaction.js +0 -178
  147. package/lib/ReactReconciler.js +0 -168
  148. package/lib/ReactRef.js +0 -80
  149. package/lib/ReactServerBatchingStrategy.js +0 -22
  150. package/lib/ReactServerRendering.js +0 -90
  151. package/lib/ReactServerRenderingTransaction.js +0 -90
  152. package/lib/ReactServerUpdateQueue.js +0 -141
  153. package/lib/ReactSimpleEmptyComponent.js +0 -37
  154. package/lib/ReactTestMount.js +0 -126
  155. package/lib/ReactTestReconcileTransaction.js +0 -121
  156. package/lib/ReactTestRenderer.js +0 -144
  157. package/lib/ReactTestUtils.js +0 -518
  158. package/lib/ReactUpdateQueue.js +0 -226
  159. package/lib/ReactUpdates.js +0 -251
  160. package/lib/ResponderEventPlugin.js +0 -510
  161. package/lib/ResponderSyntheticEvent.js +0 -39
  162. package/lib/ResponderTouchHistoryStore.js +0 -184
  163. package/lib/SVGDOMPropertyConfig.js +0 -302
  164. package/lib/SelectEventPlugin.js +0 -196
  165. package/lib/SimpleEventPlugin.js +0 -635
  166. package/lib/SyntheticAnimationEvent.js +0 -39
  167. package/lib/SyntheticClipboardEvent.js +0 -38
  168. package/lib/SyntheticCompositionEvent.js +0 -36
  169. package/lib/SyntheticDragEvent.js +0 -36
  170. package/lib/SyntheticEvent.js +0 -268
  171. package/lib/SyntheticFocusEvent.js +0 -36
  172. package/lib/SyntheticInputEvent.js +0 -37
  173. package/lib/SyntheticKeyboardEvent.js +0 -84
  174. package/lib/SyntheticMouseEvent.js +0 -72
  175. package/lib/SyntheticTouchEvent.js +0 -45
  176. package/lib/SyntheticTransitionEvent.js +0 -39
  177. package/lib/SyntheticUIEvent.js +0 -59
  178. package/lib/SyntheticWheelEvent.js +0 -54
  179. package/lib/TapEventPlugin.js +0 -110
  180. package/lib/TouchHistoryMath.js +0 -99
  181. package/lib/Transaction.js +0 -233
  182. package/lib/ViewportMetrics.js +0 -27
  183. package/lib/accumulate.js +0 -46
  184. package/lib/accumulateInto.js +0 -58
  185. package/lib/adler32.js +0 -44
  186. package/lib/createMicrosoftUnsafeLocalFunction.js +0 -32
  187. package/lib/createReactNativeComponentClass.js +0 -42
  188. package/lib/dangerousStyleValue.js +0 -79
  189. package/lib/escapeTextContentForBrowser.js +0 -123
  190. package/lib/findDOMNode.js +0 -60
  191. package/lib/findNodeHandle.js +0 -91
  192. package/lib/forEachAccumulated.js +0 -31
  193. package/lib/getEventCharCode.js +0 -50
  194. package/lib/getEventKey.js +0 -102
  195. package/lib/getEventModifierState.js +0 -43
  196. package/lib/getEventTarget.js +0 -35
  197. package/lib/getHostComponentFromComposite.js +0 -30
  198. package/lib/getNodeForCharacterOffset.js +0 -74
  199. package/lib/getTestDocument.js +0 -21
  200. package/lib/getTextContentAccessor.js +0 -33
  201. package/lib/getVendorPrefixedEventName.js +0 -101
  202. package/lib/instantiateReactComponent.js +0 -119
  203. package/lib/isEventSupported.js +0 -60
  204. package/lib/isTextInputElement.js +0 -51
  205. package/lib/quoteAttributeValueForBrowser.js +0 -26
  206. package/lib/reactComponentExpect.js +0 -217
  207. package/lib/setInnerHTML.js +0 -98
  208. package/lib/setTextContent.js +0 -48
  209. package/lib/shouldUpdateReactComponent.js +0 -42
  210. package/lib/validateDOMNesting.js +0 -382
@@ -1,119 +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 instantiateReactComponent
10
- */
11
-
12
- 'use strict';
13
-
14
- var _prodInvariant = require('./reactProdInvariant'),
15
- _assign = require('object-assign');
16
-
17
- var ReactCompositeComponent = require('./ReactCompositeComponent');
18
- var ReactEmptyComponent = require('./ReactEmptyComponent');
19
- var ReactHostComponent = require('./ReactHostComponent');
20
-
21
- var invariant = require('fbjs/lib/invariant');
22
- var warning = require('fbjs/lib/warning');
23
-
24
- // To avoid a cyclic dependency, we create the final class in this module
25
- var ReactCompositeComponentWrapper = function (element) {
26
- this.construct(element);
27
- };
28
- _assign(ReactCompositeComponentWrapper.prototype, ReactCompositeComponent.Mixin, {
29
- _instantiateReactComponent: instantiateReactComponent
30
- });
31
-
32
- function getDeclarationErrorAddendum(owner) {
33
- if (owner) {
34
- var name = owner.getName();
35
- if (name) {
36
- return ' Check the render method of `' + name + '`.';
37
- }
38
- }
39
- return '';
40
- }
41
-
42
- /**
43
- * Check if the type reference is a known internal type. I.e. not a user
44
- * provided composite type.
45
- *
46
- * @param {function} type
47
- * @return {boolean} Returns true if this is a valid internal type.
48
- */
49
- function isInternalComponentType(type) {
50
- return typeof type === 'function' && typeof type.prototype !== 'undefined' && typeof type.prototype.mountComponent === 'function' && typeof type.prototype.receiveComponent === 'function';
51
- }
52
-
53
- var nextDebugID = 1;
54
-
55
- /**
56
- * Given a ReactNode, create an instance that will actually be mounted.
57
- *
58
- * @param {ReactNode} node
59
- * @param {boolean} shouldHaveDebugID
60
- * @return {object} A new instance of the element's constructor.
61
- * @protected
62
- */
63
- function instantiateReactComponent(node, shouldHaveDebugID) {
64
- var instance;
65
-
66
- if (node === null || node === false) {
67
- instance = ReactEmptyComponent.create(instantiateReactComponent);
68
- } else if (typeof node === 'object') {
69
- var element = node;
70
- !(element && (typeof element.type === 'function' || typeof element.type === 'string')) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s', element.type == null ? element.type : typeof element.type, getDeclarationErrorAddendum(element._owner)) : _prodInvariant('130', element.type == null ? element.type : typeof element.type, getDeclarationErrorAddendum(element._owner)) : void 0;
71
-
72
- // Special case string values
73
- if (typeof element.type === 'string') {
74
- instance = ReactHostComponent.createInternalComponent(element);
75
- } else if (isInternalComponentType(element.type)) {
76
- // This is temporarily available for custom components that are not string
77
- // representations. I.e. ART. Once those are updated to use the string
78
- // representation, we can drop this code path.
79
- instance = new element.type(element);
80
-
81
- // We renamed this. Allow the old name for compat. :(
82
- if (!instance.getHostNode) {
83
- instance.getHostNode = instance.getNativeNode;
84
- }
85
- } else {
86
- instance = new ReactCompositeComponentWrapper(element);
87
- }
88
- } else if (typeof node === 'string' || typeof node === 'number') {
89
- instance = ReactHostComponent.createInstanceForText(node);
90
- } else {
91
- !false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Encountered invalid React node of type %s', typeof node) : _prodInvariant('131', typeof node) : void 0;
92
- }
93
-
94
- if (process.env.NODE_ENV !== 'production') {
95
- process.env.NODE_ENV !== 'production' ? warning(typeof instance.mountComponent === 'function' && typeof instance.receiveComponent === 'function' && typeof instance.getHostNode === 'function' && typeof instance.unmountComponent === 'function', 'Only React Components can be mounted.') : void 0;
96
- }
97
-
98
- // These two fields are used by the DOM and ART diffing algorithms
99
- // respectively. Instead of using expandos on components, we should be
100
- // storing the state needed by the diffing algorithms elsewhere.
101
- instance._mountIndex = 0;
102
- instance._mountImage = null;
103
-
104
- if (process.env.NODE_ENV !== 'production') {
105
- instance._debugID = shouldHaveDebugID ? nextDebugID++ : 0;
106
- }
107
-
108
- // Internal instances should fully constructed at this point, so they should
109
- // not get any new fields added to them at this point.
110
- if (process.env.NODE_ENV !== 'production') {
111
- if (Object.preventExtensions) {
112
- Object.preventExtensions(instance);
113
- }
114
- }
115
-
116
- return instance;
117
- }
118
-
119
- module.exports = instantiateReactComponent;
@@ -1,60 +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 isEventSupported
10
- */
11
-
12
- 'use strict';
13
-
14
- var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
15
-
16
- var useHasFeature;
17
- if (ExecutionEnvironment.canUseDOM) {
18
- useHasFeature = document.implementation && document.implementation.hasFeature &&
19
- // always returns true in newer browsers as per the standard.
20
- // @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
21
- document.implementation.hasFeature('', '') !== true;
22
- }
23
-
24
- /**
25
- * Checks if an event is supported in the current execution environment.
26
- *
27
- * NOTE: This will not work correctly for non-generic events such as `change`,
28
- * `reset`, `load`, `error`, and `select`.
29
- *
30
- * Borrows from Modernizr.
31
- *
32
- * @param {string} eventNameSuffix Event name, e.g. "click".
33
- * @param {?boolean} capture Check if the capture phase is supported.
34
- * @return {boolean} True if the event is supported.
35
- * @internal
36
- * @license Modernizr 3.0.0pre (Custom Build) | MIT
37
- */
38
- function isEventSupported(eventNameSuffix, capture) {
39
- if (!ExecutionEnvironment.canUseDOM || capture && !('addEventListener' in document)) {
40
- return false;
41
- }
42
-
43
- var eventName = 'on' + eventNameSuffix;
44
- var isSupported = eventName in document;
45
-
46
- if (!isSupported) {
47
- var element = document.createElement('div');
48
- element.setAttribute(eventName, 'return;');
49
- isSupported = typeof element[eventName] === 'function';
50
- }
51
-
52
- if (!isSupported && useHasFeature && eventNameSuffix === 'wheel') {
53
- // This is the only way to test support for the `wheel` event in IE9+.
54
- isSupported = document.implementation.hasFeature('Events.wheel', '3.0');
55
- }
56
-
57
- return isSupported;
58
- }
59
-
60
- module.exports = isEventSupported;
@@ -1,51 +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 isTextInputElement
10
- *
11
- */
12
-
13
- 'use strict';
14
-
15
- /**
16
- * @see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
17
- */
18
-
19
- var supportedInputTypes = {
20
- 'color': true,
21
- 'date': true,
22
- 'datetime': true,
23
- 'datetime-local': true,
24
- 'email': true,
25
- 'month': true,
26
- 'number': true,
27
- 'password': true,
28
- 'range': true,
29
- 'search': true,
30
- 'tel': true,
31
- 'text': true,
32
- 'time': true,
33
- 'url': true,
34
- 'week': true
35
- };
36
-
37
- function isTextInputElement(elem) {
38
- var nodeName = elem && elem.nodeName && elem.nodeName.toLowerCase();
39
-
40
- if (nodeName === 'input') {
41
- return !!supportedInputTypes[elem.type];
42
- }
43
-
44
- if (nodeName === 'textarea') {
45
- return true;
46
- }
47
-
48
- return false;
49
- }
50
-
51
- module.exports = isTextInputElement;
@@ -1,26 +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 quoteAttributeValueForBrowser
10
- */
11
-
12
- 'use strict';
13
-
14
- var escapeTextContentForBrowser = require('./escapeTextContentForBrowser');
15
-
16
- /**
17
- * Escapes attribute value to prevent scripting attacks.
18
- *
19
- * @param {*} value Value to escape.
20
- * @return {string} An escaped string.
21
- */
22
- function quoteAttributeValueForBrowser(value) {
23
- return '"' + escapeTextContentForBrowser(value) + '"';
24
- }
25
-
26
- module.exports = quoteAttributeValueForBrowser;
@@ -1,217 +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 reactComponentExpect
10
- */
11
-
12
- 'use strict';
13
-
14
- var _prodInvariant = require('./reactProdInvariant'),
15
- _assign = require('object-assign');
16
-
17
- var ReactInstanceMap = require('./ReactInstanceMap');
18
- var ReactTestUtils = require('./ReactTestUtils');
19
-
20
- var invariant = require('fbjs/lib/invariant');
21
-
22
- function reactComponentExpect(instance) {
23
- if (instance instanceof reactComponentExpectInternal) {
24
- return instance;
25
- }
26
-
27
- if (!(this instanceof reactComponentExpect)) {
28
- return new reactComponentExpect(instance);
29
- }
30
-
31
- expect(instance).not.toBeNull();
32
- expect(instance).not.toBeUndefined();
33
-
34
- !ReactTestUtils.isCompositeComponent(instance) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'reactComponentExpect(...): instance must be a composite component') : _prodInvariant('15') : void 0;
35
- var internalInstance = ReactInstanceMap.get(instance);
36
-
37
- expect(typeof internalInstance).toBe('object');
38
- expect(typeof internalInstance.constructor).toBe('function');
39
- expect(ReactTestUtils.isElement(internalInstance)).toBe(false);
40
-
41
- return new reactComponentExpectInternal(internalInstance);
42
- }
43
-
44
- function reactComponentExpectInternal(internalInstance) {
45
- this._instance = internalInstance;
46
- }
47
-
48
- _assign(reactComponentExpectInternal.prototype, {
49
- // Getters -------------------------------------------------------------------
50
-
51
- /**
52
- * @instance: Retrieves the backing instance.
53
- */
54
- instance: function () {
55
- return this._instance.getPublicInstance();
56
- },
57
-
58
- /**
59
- * There are two types of components in the world.
60
- * - A component created via React.createClass() - Has a single child
61
- * subComponent - the return value from the .render() function. This
62
- * function @subComponent expects that this._instance is component created
63
- * with React.createClass().
64
- * - A primitive DOM component - which has many renderedChildren, each of
65
- * which may have a name that is unique with respect to its siblings. This
66
- * method will fail if this._instance is a primitive component.
67
- *
68
- * TL;DR: An instance may have a subComponent (this._renderedComponent) or
69
- * renderedChildren, but never both. Neither will actually show up until you
70
- * render the component (simply instantiating is not enough).
71
- */
72
- expectRenderedChild: function () {
73
- this.toBeCompositeComponent();
74
- var child = this._instance._renderedComponent;
75
- // TODO: Hide ReactEmptyComponent instances here?
76
- return new reactComponentExpectInternal(child);
77
- },
78
-
79
- /**
80
- * The nth child of a DOMish component instance that is not falsy.
81
- */
82
- expectRenderedChildAt: function (childIndex) {
83
- // Currently only dom components have arrays of children, but that will
84
- // change soon.
85
- this.toBeDOMComponent();
86
- var renderedChildren = this._instance._renderedChildren || {};
87
- for (var name in renderedChildren) {
88
- if (!renderedChildren.hasOwnProperty(name)) {
89
- continue;
90
- }
91
- if (renderedChildren[name]) {
92
- if (renderedChildren[name]._mountIndex === childIndex) {
93
- return new reactComponentExpectInternal(renderedChildren[name]);
94
- }
95
- }
96
- }
97
- throw new Error('Child:' + childIndex + ' is not found');
98
- },
99
-
100
- toBeDOMComponentWithChildCount: function (count) {
101
- this.toBeDOMComponent();
102
- var renderedChildren = this._instance._renderedChildren;
103
- expect(renderedChildren).toBeTruthy();
104
- expect(Object.keys(renderedChildren).length).toBe(count);
105
- return this;
106
- },
107
-
108
- toBeDOMComponentWithNoChildren: function () {
109
- this.toBeDOMComponent();
110
- expect(this._instance._renderedChildren).toBeFalsy();
111
- return this;
112
- },
113
-
114
- // Matchers ------------------------------------------------------------------
115
-
116
- toBeComponentOfType: function (constructor) {
117
- expect(this._instance._currentElement.type === constructor).toBe(true);
118
- return this;
119
- },
120
-
121
- /**
122
- * A component that is created with React.createClass. Just duck typing
123
- * here.
124
- */
125
- toBeCompositeComponent: function () {
126
- expect(typeof this.instance() === 'object' && typeof this.instance().render === 'function').toBe(true);
127
- return this;
128
- },
129
-
130
- toBeCompositeComponentWithType: function (constructor) {
131
- this.toBeCompositeComponent();
132
- expect(this._instance._currentElement.type === constructor).toBe(true);
133
- return this;
134
- },
135
-
136
- toBeTextComponentWithValue: function (val) {
137
- var elementType = typeof this._instance._currentElement;
138
- expect(elementType === 'string' || elementType === 'number').toBe(true);
139
- expect(this._instance._stringText).toBe(val);
140
- return this;
141
- },
142
-
143
- toBeEmptyComponent: function () {
144
- var element = this._instance._currentElement;
145
- return element === null || element === false;
146
- },
147
-
148
- toBePresent: function () {
149
- expect(this.instance()).toBeTruthy();
150
- return this;
151
- },
152
-
153
- /**
154
- * A terminal type of component representing some virtual dom node. Just duck
155
- * typing here.
156
- */
157
- toBeDOMComponent: function () {
158
- expect(ReactTestUtils.isDOMComponent(this.instance())).toBe(true);
159
- return this;
160
- },
161
-
162
- /**
163
- * @deprecated
164
- * @see toBeComponentOfType
165
- */
166
- toBeDOMComponentWithTag: function (tag) {
167
- this.toBeDOMComponent();
168
- expect(this.instance().tagName).toBe(tag.toUpperCase());
169
- return this;
170
- },
171
-
172
- /**
173
- * Check that internal state values are equal to a state of expected values.
174
- */
175
- scalarStateEqual: function (stateNameToExpectedValue) {
176
- expect(this.instance()).toBeTruthy();
177
- for (var stateName in stateNameToExpectedValue) {
178
- if (!stateNameToExpectedValue.hasOwnProperty(stateName)) {
179
- continue;
180
- }
181
- expect(this.instance().state[stateName]).toEqual(stateNameToExpectedValue[stateName]);
182
- }
183
- return this;
184
- },
185
-
186
- /**
187
- * Check a set of props are equal to a set of expected values - only works
188
- * with scalars.
189
- */
190
- scalarPropsEqual: function (propNameToExpectedValue) {
191
- expect(this.instance()).toBeTruthy();
192
- for (var propName in propNameToExpectedValue) {
193
- if (!propNameToExpectedValue.hasOwnProperty(propName)) {
194
- continue;
195
- }
196
- expect(this.instance().props[propName]).toEqual(propNameToExpectedValue[propName]);
197
- }
198
- return this;
199
- },
200
-
201
- /**
202
- * Check a set of props are equal to a set of expected values - only works
203
- * with scalars.
204
- */
205
- scalarContextEqual: function (contextNameToExpectedValue) {
206
- expect(this.instance()).toBeTruthy();
207
- for (var contextName in contextNameToExpectedValue) {
208
- if (!contextNameToExpectedValue.hasOwnProperty(contextName)) {
209
- continue;
210
- }
211
- expect(this.instance().context[contextName]).toEqual(contextNameToExpectedValue[contextName]);
212
- }
213
- return this;
214
- }
215
- });
216
-
217
- module.exports = reactComponentExpect;