From 3b9982487c3b68708cc34a107b0d058336d87459 Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Mon, 21 Nov 2016 16:40:09 -0500 Subject: [PATCH] [added] react v15.4 support --- package.json | 2 +- src/element.js | 4 ++-- src/utils.js | 31 +++++++++++++++++++++---------- test/common.js | 1 - 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 16d8fb3..3ea8209 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "webpack": "^1.12.2" }, "dependencies": { - "bill": "^3.2.1", + "bill": "^3.2.6", "dom-helpers": "^2.4.0", "invariant": "^2.2.0", "lodash": "^3.10.1", diff --git a/src/element.js b/src/element.js index 84c7b6d..0eac083 100644 --- a/src/element.js +++ b/src/element.js @@ -30,8 +30,8 @@ function spyOnUpdate(inst, fn) { let didUpdate = inst.componentDidUpdate; inst.componentDidUpdate = function(...args) { - fn(...args) - didUpdate && didUpdate(...args) + fn.apply(this, args) + didUpdate && didUpdate.apply(this, args) } } diff --git a/src/utils.js b/src/utils.js index f07eedc..67783c7 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,15 +1,25 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import { - getID, getNode, findReactContainerForID - , getReactRootID, _instancesByReactRootID } from 'react/lib/ReactMount'; -import ReactTestUtils from'react-addons-test-utils'; +import ReactTestUtils from 'react-addons-test-utils'; import invariant from 'invariant'; import bill from 'bill'; import { ifDef } from 'bill/compat'; import { createNode, NODE_TYPES } from 'bill/node'; +let ReactMount = {}; + +try { + ReactMount = ifDef({ + '>=15.4.x': () => require('react-dom/lib/ReactMount'), + '*': () => require('react/lib/ReactMount') + })(); +} catch (err) { /* empty */ } + +let { + getID, getNode, findReactContainerForID + , getReactRootID, _instancesByReactRootID } = ReactMount; + export let isDOMComponent = ReactTestUtils.isDOMComponent; export function assertLength(collection, method) { @@ -176,14 +186,15 @@ export function wrapElement(element, context, prevWrapper) { } export let getMountPoint = ifDef({ - '<15': function getMountPoint(instance) { - var id = getID(findDOMNode(instance)); - return findReactContainerForID(id); - }, - '*': function getMountPoint(instance) { + '>=15.x.x': function getMountPoint(instance) { let privInst = createNode(instance).privateInstance - let container = createNode(privInst._nativeContainerInfo._topLevelWrapper) + let info = privInst._nativeContainerInfo || privInst._hostContainerInfo; + let container = createNode(info._topLevelWrapper) return findDOMNode(container.instance).parentNode + }, + '*': function getMountPoint(instance) { + var id = getID(findDOMNode(instance)); + return findReactContainerForID(id); } }) diff --git a/test/common.js b/test/common.js index 43259c2..3bad4da 100644 --- a/test/common.js +++ b/test/common.js @@ -274,7 +274,6 @@ describe('common', ()=> { }) it('props() should change props', ()=> { - render() .tap(inst => { inst.first('div > :text').unwrap()