mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-25 09:43:21 +01:00
* Add `editor.hasCommand` method * Add `editor.hasQuery` method * Rename directories `hasCommand` and `hasQuery` to kebab case * Add tests for `editor.hasCommand` of React component * Add tests for `editor.hasQuery` of React component
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import assert from 'assert'
|
|
import clean from './helpers/clean'
|
|
import React from 'react'
|
|
import ReactDOM from 'react-dom/server'
|
|
import ShallowRenderer from 'react-test-renderer/shallow'
|
|
import { Editor } from 'slate-react'
|
|
import { fixtures } from 'slate-dev-test-utils'
|
|
import { JSDOM } from 'jsdom'
|
|
|
|
describe('slate-react', () => {
|
|
fixtures(__dirname, 'components', ({ module }) => {
|
|
const { input, output, default: fn } = module
|
|
|
|
const renderer = new ShallowRenderer()
|
|
renderer.render(React.createElement(Editor, input, null))
|
|
const editor = renderer.getRenderOutput().props.editor
|
|
|
|
const actual = fn(editor)
|
|
const expected = output
|
|
|
|
assert.equal(actual, expected)
|
|
})
|
|
|
|
fixtures(__dirname, 'rendering/fixtures', ({ module }) => {
|
|
const { value, output, props } = module
|
|
const p = {
|
|
value,
|
|
onChange() {},
|
|
...(props || {}),
|
|
}
|
|
|
|
const string = ReactDOM.renderToStaticMarkup(<Editor {...p} />)
|
|
const dom = JSDOM.fragment(output)
|
|
const expected = dom.firstChild.outerHTML
|
|
.trim()
|
|
.replace(/\n/gm, '')
|
|
.replace(/>\s*</g, '><')
|
|
|
|
assert.equal(clean(string), expected)
|
|
})
|
|
})
|