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

c.destroy broken test against master #103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/__test__/kitchensink.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these two lines add anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They use to, but the code that used it was moved to the regression test file. It might be useful to keep them as they are such a common tool to use with Rx anyway.

import 'rxjs/add/operator/scan'
import 'rxjs/add/operator/startWith'
import 'rxjs/add/operator/combineLatest'
Expand Down
111 changes: 111 additions & 0 deletions src/__test__/regression.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/* @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(`Issues regression tests`, () => {
it(`Adds jsx null/empty elements`, () => {
function NullChildren () {
return h(`div`, {id: `children`}, [
null,
Observable.from([null]),
``,
Observable.from([``]),
Observable.of(h(`p`, null, `actual child`)),
])
}

const vnode = h(NullChildren)
const {node, cleanup} = renderInDocument(vnode)

assert.equal(node.children.length, 1)
cleanup()
})

it(`Removes simple children with text after clicking without keys: #101`, () => {
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 = h(`b`, {}, `b element`)
else if (tag === `p`) elem = h(`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 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 = h(DestroyChildren)
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()
})
})