Resolve Flow & Test issues with ReactTestRenderer

This is a manual cherry-pick of 2 PRs, updated to handle differences in the stable branch:
- c78464f8ea - Resolve flow errors with ReactTestRenderer (#7736)
- 7dfa01f9fa - Revert ReactMultiChild to plain object (#7757)
This commit is contained in:
Brandon Dail
2016-10-04 15:22:03 -07:00
committed by Paul O’Shannessy
parent c7020c017d
commit 91dc94cec6
6 changed files with 24 additions and 7 deletions
@@ -15,6 +15,7 @@
var invariant = require('invariant');
import type { ReactInstance } from 'ReactInstanceType';
import type { Transaction } from 'Transaction';
/**
* @param {?object} object
@@ -73,7 +74,7 @@ var ReactOwner = {
component: ReactInstance,
ref: string,
owner: ReactInstance,
transaction,
transaction: Transaction,
): void {
invariant(
isValidOwner(owner),
@@ -13,6 +13,8 @@
'use strict';
class ReactTestEmptyComponent {
_currentElement: null;
constructor() {
this._currentElement = null;
}
+4 -2
View File
@@ -20,8 +20,10 @@ var getHostComponentFromComposite = require('getHostComponentFromComposite');
var instantiateReactComponent = require('instantiateReactComponent');
var invariant = require('invariant');
type TestRendererOptions = {
createNodeMock: (element: ReactElement) => Object,
import type { ReactElement } from 'ReactElementType';
export type TestRendererOptions = {
createNodeMock: (element: ReactElement) => any,
};
var defaultTestOptions = {
@@ -16,6 +16,8 @@ var PooledClass = require('PooledClass');
var Transaction = require('Transaction');
var ReactUpdateQueue = require('ReactUpdateQueue');
import type { TestRendererOptions } from 'ReactTestMount';
/**
* Provides a `CallbackQueue` queue for collecting `onDOMReady` callbacks during
* the performing of the transaction.
@@ -57,7 +59,7 @@ var TRANSACTION_WRAPPERS = [ON_DOM_READY_QUEUEING];
*
* @class ReactTestReconcileTransaction
*/
function ReactTestReconcileTransaction(testOptions) {
function ReactTestReconcileTransaction(testOptions: TestRendererOptions) {
this.reinitializeTransaction();
this.testOptions = testOptions;
this.reactMountReady = CallbackQueue.getPooled(this);
+11 -3
View File
@@ -24,11 +24,13 @@ var ReactTestTextComponent = require('ReactTestTextComponent');
var ReactTestEmptyComponent = require('ReactTestEmptyComponent');
import type { ReactElement } from 'ReactElementType';
import type { ReactInstance } from 'ReactInstanceType';
type ReactTestRendererJSON = {
type: string,
props: { [propName: string]: string },
children: Array<string | ReactTestRendererJSON>,
children: null | Array<string | ReactTestRendererJSON>,
$$typeof?: any
}
/**
@@ -47,6 +49,10 @@ function getRenderedHostOrTextFromComponent(component) {
}
class ReactTestComponent {
_currentElement: ReactElement;
_renderedChildren: null | Object;
_topLevelWrapper: null | ReactInstance;
constructor(element: ReactElement) {
this._currentElement = element;
this._renderedChildren = null;
@@ -60,6 +66,7 @@ class ReactTestComponent {
context: Object,
) {
var element = this._currentElement;
// $FlowFixMe https://github.com/facebook/flow/issues/1805
this.mountChildren(element.props.children, transaction, context);
}
@@ -69,6 +76,7 @@ class ReactTestComponent {
context: Object,
) {
this._currentElement = nextElement;
// $FlowFixMe https://github.com/facebook/flow/issues/1805
this.updateChildren(nextElement.props.children, transaction, context);
}
@@ -89,7 +97,7 @@ class ReactTestComponent {
childrenJSON.push(json);
}
}
var object = {
var object: ReactTestRendererJSON = {
type: this._currentElement.type,
props: props,
children: childrenJSON.length ? childrenJSON : null,
@@ -104,7 +112,7 @@ class ReactTestComponent {
unmountComponent(): void {}
}
Object.assign(ReactTestComponent.prototype, ReactMultiChild);
Object.assign(ReactTestComponent.prototype, ReactMultiChild.Mixin);
// =============================================================================
@@ -15,6 +15,8 @@
import type { ReactText } from 'ReactTypes';
class ReactTestTextComponent {
_currentElement: ReactText;
constructor(element: ReactText) {
this._currentElement = element;
}