Skip to content
This repository has been archived by the owner on Sep 20, 2018. It is now read-only.

Commit

Permalink
[added] react 15 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Apr 8, 2016
1 parent 503f14c commit 22e192a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 19 deletions.
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = function (config) {
},

webpack: {
devtool: 'inline-source-map',
module: {
loaders: [{ test: /\.js$/, loader: 'babel', exclude: /node_modules/ }]
}
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"invariant": "^2.2.0",
"lodash": "^3.10.1",
"promise": "^7.1.1",
"react-addons-test-utils": "^0.14.0-rc1",
"react-addons-test-utils": "^0.14.0-rc1 || ^15.0",
"warning": "^2.1.0"
}
}
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
"description": "jQuery-esque Api for React elements and instances, supports complex css selectors",
"main": "lib/index.js",
"scripts": {
"test": "karma start --single-run",
"test": "npm run react:14 && npm run test-current && npm run react:15 && npm run test-current",
"test-current": "karma start --single-run",
"tdd": "karma start",
"toc": "doctoc README.md --github",
"react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils",
"react:14": "npm run react:clean && npm i react@0.14 react-dom@0.14 react-addons-test-utils@0.14",
"react:15": "npm run react:clean && npm i react@15 react-dom@15 react-addons-test-utils@15",
"build": "babel src --out-dir lib && npm run toc && cpy ./README.md ./lib",
"release": "release"
},
Expand All @@ -26,8 +30,8 @@
},
"homepage": "https://github.com/jquense/teaspoon",
"peerDependencies": {
"react": "^0.14.0-rc1",
"react-dom": "^0.14.0-rc1"
"react": "^0.14.0-rc1 || ^15.0.0",
"react-dom": "^0.14.0-rc1 || ^15.0.0"
},
"devDependencies": {
"babel": "^5.8.25",
Expand All @@ -52,24 +56,21 @@
"karma-webpack": "^1.7.0",
"mocha": "^2.3.3",
"mt-changelog": "^0.6.2",
"react": "^0.14.3",
"react-dom": "^0.14.0-rc1",
"release-script": "^0.5.3",
"release-script": "^1.0.2",
"sinon": "^1.17.1",
"sinon-chai": "^2.8.0",
"webpack": "^1.12.2"
},
"dependencies": {
"bill": "^3.1.0",
"bill": "^3.2.1",
"dom-helpers": "^2.4.0",
"invariant": "^2.2.0",
"lodash": "^3.10.1",
"promise": "^7.1.1",
"react-addons-test-utils": "^0.14.0-rc1",
"react-addons-test-utils": "^0.14.0-rc1 || ^15.0",
"warning": "^2.1.0"
},
"release-script": {
"defaultDryRun": "false",
"altPkgRootFolder": "lib"
}
}
19 changes: 13 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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';

export let isDOMComponent = ReactTestUtils.isDOMComponent;
Expand Down Expand Up @@ -62,7 +63,7 @@ export function render(element, mount, { props, context }, renderFn) {

if (!renderInstance)
renderInstance = instance

if (instance === null) {
renderInstance = null;
wrapper = wrapElement(element, null, prevWrapper)
Expand Down Expand Up @@ -175,11 +176,17 @@ export function wrapElement(element, context, prevWrapper) {
return <TspWrapper context={context}>{element}</TspWrapper>
}


export function getMountPoint(instance){
var id = getID(findDOMNode(instance));
return findReactContainerForID(id);
}
export let getMountPoint = ifDef({
'<15': function getMountPoint(instance) {
var id = getID(findDOMNode(instance));
return findReactContainerForID(id);
},
'*': function getMountPoint(instance) {
let privInst = createNode(instance).privateInstance
let container = createNode(privInst._nativeContainerInfo._topLevelWrapper)
return findDOMNode(container.instance).parentNode
}
})

export function getRootInstance(mountPoint){
return _instancesByReactRootID[getReactRootID(mountPoint)];
Expand Down
2 changes: 1 addition & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('common', ()=> {
inst.is(Stateless).should.equal(true)
})

it.only('.end()', () => {
it('.end()', () => {
render(<Example />)
.find(Stateless)
.find('strong')
Expand Down
13 changes: 11 additions & 2 deletions test/dom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render } from 'react-dom';
import { render, findDOMNode } from 'react-dom';
import $ from '../src';

describe('DOM rendering specific', ()=> {
Expand Down Expand Up @@ -36,13 +36,22 @@ describe('DOM rendering specific', ()=> {
}

it('should wrap existing mounted component', ()=> {
class Div extends React.Component {
render(){ return <div {...this.props} /> }
}
let mount = document.createElement('div')
, instance = render(<div className='test'/>, mount)
, instance = render(<Div className='test'><span/></Div>, mount)

let $inst = $(instance);

expect($inst[0]).to.equal(instance);
expect($inst._mountPoint).to.equal(mount)

let span = findDOMNode(instance).children[0];
$inst = $(span);

expect($inst[0]).to.equal(span);
expect($inst._mountPoint).to.equal(mount)
})

it('should unmount', ()=> {
Expand Down

0 comments on commit 22e192a

Please sign in to comment.