1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-24 16:02:55 +02:00

slate-hyperscript: Fix extra empty text at the end of children (#1379)

* Add failing test

* Don't push extra text node at the end of children

* Fix keys in tests

* Add option `normalize` to <value>

* Write Changelog

* Changelog on correct  package

* Fix preserve keys test

* Fix tests (which make more sense now)

* Mark failing test as skipped

* Account for skip option

* Lint and fix changelog version

* Use Unreleased instead of version

* Lint markdown
This commit is contained in:
Nicolas Gaborit
2018-04-27 22:16:11 +02:00
committed by Ian Storm Taylor
parent a943eada85
commit 099c6ada72
19 changed files with 131 additions and 27 deletions

View File

@@ -0,0 +1,75 @@
/** @jsx h */
import h from '../'
import assert from 'assert'
import { Value, Document, Block, Text } from 'slate'
describe('slate-hyperscript', () => {
it('should create a document with a single block', () => {
const output = (
<document>
<block type="paragraph">Single block</block>
</document>
)
const expected = Document.create({
nodes: [
Block.create({
type: 'paragraph',
nodes: [Text.create('Single block')],
}),
],
})
assert.deepEqual(output.toJSON(), expected.toJSON())
})
it('should normalize a value by default', () => {
const output = (
<value>
<document>
<block type="paragraph">Valid block</block>
<text>Invalid text</text>
</document>
</value>
)
const expected = Value.create({
document: Document.create({
nodes: [
Block.create({
type: 'paragraph',
nodes: [Text.create('Valid block')],
}),
],
}),
})
assert.deepEqual(output.toJSON(), expected.toJSON())
})
it('should not normalize a value, given the option', () => {
const output = (
<value normalize={false}>
<document>
<block type="paragraph">Valid block</block>
<text>Invalid text</text>
</document>
</value>
)
const expected = Value.fromJSON(
{
document: Document.create({
nodes: [
Block.create({
type: 'paragraph',
nodes: [Text.create('Valid block')],
}),
Text.create('Invalid text'),
],
}),
},
{ normalize: false }
)
assert.deepEqual(output.toJSON(), expected.toJSON())
})
})