From ec1d63342662dfe51ed9d04af5e3c3b8de96fe2f Mon Sep 17 00:00:00 2001 From: Jonathan Dunlap Date: Sun, 8 May 2016 15:39:45 -0700 Subject: [PATCH 1/2] added c.destroy broken test against master --- .babelrc | 8 +- package.json | 1 + src/__test__/kitchensink.jsx.test.js | 121 +++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 src/__test__/kitchensink.jsx.test.js diff --git a/.babelrc b/.babelrc index 80cb370..c1c0c21 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,12 @@ { "presets": ["es2015", "stage-0"], "plugins": [ - ["transform-flow-comments"] + ["transform-flow-comments"], + [ + "transform-react-jsx", + { + "pragma": "h" + } + ] ] } diff --git a/package.json b/package.json index 1939c12..5ec09b2 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "babel-eslint": "6.0.2", "babel-loader": "6.2.4", "babel-plugin-transform-flow-comments": "6.7.0", + "babel-plugin-transform-react-jsx": "^6.8.0", "babel-preset-es2015": "6.6.0", "babel-preset-stage-0": "6.5.0", "chai": "3.5.0", diff --git a/src/__test__/kitchensink.jsx.test.js b/src/__test__/kitchensink.jsx.test.js new file mode 100644 index 0000000..8d84cc8 --- /dev/null +++ b/src/__test__/kitchensink.jsx.test.js @@ -0,0 +1,121 @@ +/* @flow weak */ + +import $ from 'jquery' +import {Observable} from 'rxjs/Observable' +import {renderInDocument} from './support/renderInDocument' +import {h} from '../h' + +import 'rxjs/add/observable/interval' +import 'rxjs/add/observable/from' +import 'rxjs/add/observable/of' +import 'rxjs/add/operator/map' +import 'rxjs/add/operator/merge' +import 'rxjs/add/operator/mergeMap' +import 'rxjs/add/operator/scan' +import 'rxjs/add/operator/startWith' +import 'rxjs/add/operator/combineLatest' + +describe(`kitchen sink of jsx tests`, () => { + it(`Adds jsx null/empty elements`, () => { + function NullChildren () { + return ( +
+
+ {null} + {Observable.from([null])} + {``} + {Observable.from([``])} + {Observable.of(

actual child

)} +
+
+ ) + } + + const component = h(NullChildren) + const {node, cleanup} = renderInDocument(component) + + const children = node.querySelector(`#children`) + + assert.equal(children.children.length, 1) + cleanup() + }) + + it(`removes jsx children after clicking without keys`, () => { + function DestroyChildren ({createEventHandler}) { + const handleAdd = createEventHandler(1) + const handleRemove = createEventHandler(-1) + + const lenToElements = tag => (len: number) => { + const els = Array(len) + let i = -1 + + while (++i < len) { + let elem = null + if (tag === `b`) elem = b element + else if (tag === `p`) elem =

p element

+ + els[i] = elem + } + + return els + } + + const addable = handleAdd.scan((acc, i) => acc + i, 1).startWith(1).map(lenToElements(`b`)) + const removeable = handleRemove.scan((acc, i) => acc + i, 4).startWith(4).map(lenToElements(`p`)) + + return ( +
+
+ {addable} + {removeable} +
+ + +
+ ) + } + + const component = + const {node, cleanup} = renderInDocument(component) + + const adder = $(`#add`) + const remover = $(`#remove`) + const children = node.querySelector(`#children`) + + assert.equal(children.children.length, 5) + assert.equal(children.children[0].tagName, `B`) + assert.equal(children.children[1].tagName, `P`) + assert.equal(children.children[2].tagName, `P`) + assert.equal(children.children[3].tagName, `P`) + assert.equal(children.children[4].tagName, `P`) + + remover.trigger(`click`) + + assert.equal(children.children.length, 4) + assert.equal(children.children[0].tagName, `B`) + assert.equal(children.children[1].tagName, `P`) + assert.equal(children.children[2].tagName, `P`) + assert.equal(children.children[3].tagName, `P`) + + remover.trigger(`click`) + remover.trigger(`click`) + + assert.equal(children.children.length, 2) + assert.equal(children.children[0].tagName, `B`) + assert.equal(children.children[1].tagName, `P`) + + adder.trigger(`click`) + adder.trigger(`click`) + + assert.equal(children.children.length, 4) + assert.equal(children.children[0].tagName, `B`) + assert.equal(children.children[1].tagName, `B`) + assert.equal(children.children[2].tagName, `B`) + assert.equal(children.children[3].tagName, `P`) + + cleanup() + }) +}) + +/* eslint react/prop-types: 0 */ +/* eslint react/react-in-jsx-scope: 0 */ From f089ea3759c088249dfc6481ea99e323854a1924 Mon Sep 17 00:00:00 2001 From: Jonathan Dunlap Date: Mon, 9 May 2016 16:42:07 -0700 Subject: [PATCH 2/2] Added regression test file + changed tests to use hyperscript --- .babelrc | 8 +-- package.json | 1 - src/__test__/kitchensink.test.js | 2 + ...hensink.jsx.test.js => regression.test.js} | 58 ++++++++----------- 4 files changed, 27 insertions(+), 42 deletions(-) rename src/__test__/{kitchensink.jsx.test.js => regression.test.js} (69%) diff --git a/.babelrc b/.babelrc index c1c0c21..80cb370 100644 --- a/.babelrc +++ b/.babelrc @@ -1,12 +1,6 @@ { "presets": ["es2015", "stage-0"], "plugins": [ - ["transform-flow-comments"], - [ - "transform-react-jsx", - { - "pragma": "h" - } - ] + ["transform-flow-comments"] ] } diff --git a/package.json b/package.json index 5ec09b2..1939c12 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "babel-eslint": "6.0.2", "babel-loader": "6.2.4", "babel-plugin-transform-flow-comments": "6.7.0", - "babel-plugin-transform-react-jsx": "^6.8.0", "babel-preset-es2015": "6.6.0", "babel-preset-stage-0": "6.5.0", "chai": "3.5.0", diff --git a/src/__test__/kitchensink.test.js b/src/__test__/kitchensink.test.js index cdb0e59..92ff997 100644 --- a/src/__test__/kitchensink.test.js +++ b/src/__test__/kitchensink.test.js @@ -9,9 +9,11 @@ import {noop} from '../noop' import {render} from '../render' import {renderInDocument} from './support/renderInDocument' +import 'rxjs/add/observable/from' import 'rxjs/add/observable/interval' import 'rxjs/add/operator/map' import 'rxjs/add/operator/merge' +import 'rxjs/add/observable/of' import 'rxjs/add/operator/scan' import 'rxjs/add/operator/startWith' import 'rxjs/add/operator/combineLatest' diff --git a/src/__test__/kitchensink.jsx.test.js b/src/__test__/regression.test.js similarity index 69% rename from src/__test__/kitchensink.jsx.test.js rename to src/__test__/regression.test.js index 8d84cc8..10218ed 100644 --- a/src/__test__/kitchensink.jsx.test.js +++ b/src/__test__/regression.test.js @@ -15,32 +15,26 @@ import 'rxjs/add/operator/scan' import 'rxjs/add/operator/startWith' import 'rxjs/add/operator/combineLatest' -describe(`kitchen sink of jsx tests`, () => { +describe(`Issues regression tests`, () => { it(`Adds jsx null/empty elements`, () => { function NullChildren () { - return ( -
-
- {null} - {Observable.from([null])} - {``} - {Observable.from([``])} - {Observable.of(

actual child

)} -
-
- ) + return h(`div`, {id: `children`}, [ + null, + Observable.from([null]), + ``, + Observable.from([``]), + Observable.of(h(`p`, null, `actual child`)), + ]) } - const component = h(NullChildren) - const {node, cleanup} = renderInDocument(component) - - const children = node.querySelector(`#children`) + const vnode = h(NullChildren) + const {node, cleanup} = renderInDocument(vnode) - assert.equal(children.children.length, 1) + assert.equal(node.children.length, 1) cleanup() }) - it(`removes jsx children after clicking without keys`, () => { + it(`Removes simple children with text after clicking without keys: #101`, () => { function DestroyChildren ({createEventHandler}) { const handleAdd = createEventHandler(1) const handleRemove = createEventHandler(-1) @@ -51,8 +45,8 @@ describe(`kitchen sink of jsx tests`, () => { while (++i < len) { let elem = null - if (tag === `b`) elem = b element - else if (tag === `p`) elem =

p element

+ if (tag === `b`) elem = h(`b`, {}, `b element`) + else if (tag === `p`) elem = h(`p`, {}, `element`) els[i] = elem } @@ -63,19 +57,18 @@ describe(`kitchen sink of jsx tests`, () => { const addable = handleAdd.scan((acc, i) => acc + i, 1).startWith(1).map(lenToElements(`b`)) const removeable = handleRemove.scan((acc, i) => acc + i, 4).startWith(4).map(lenToElements(`p`)) - return ( -
-
- {addable} - {removeable} -
- - -
- ) + return h(`div`, {id: `layer1`}, + Observable.of(``), + h(`div`, {id: `children`}, [ + addable, + removeable, + ]), + h(`button`, {id: `add`, onClick: handleAdd}), + h(`button`, {id: `remove`, onClick: handleRemove}) + ) } - const component = + const component = h(DestroyChildren) const {node, cleanup} = renderInDocument(component) const adder = $(`#add`) @@ -116,6 +109,3 @@ describe(`kitchen sink of jsx tests`, () => { cleanup() }) }) - -/* eslint react/prop-types: 0 */ -/* eslint react/react-in-jsx-scope: 0 */