2018-08-06 13:31:42 -04:00
|
|
|
import Html from 'slate-html-serializer'
|
2017-09-11 18:11:45 -07:00
|
|
|
import assert from 'assert'
|
2018-08-01 09:16:02 -07:00
|
|
|
import { JSDOM } from 'jsdom'
|
|
|
|
import { Value } from 'slate'
|
|
|
|
import { fixtures } from 'slate-dev-test-utils'
|
2017-09-11 18:11:45 -07:00
|
|
|
|
|
|
|
describe('slate-html-serializer', () => {
|
2018-08-01 09:16:02 -07:00
|
|
|
fixtures(__dirname, 'deserialize', ({ module }) => {
|
|
|
|
const { input, output, config, options } = module
|
|
|
|
const html = new Html({ parseHtml: JSDOM.fragment, ...config })
|
|
|
|
const value = html.deserialize(input, options)
|
|
|
|
const actual = Value.isValue(value) ? value.toJSON() : value
|
|
|
|
const expected = Value.isValue(output) ? output.toJSON() : output
|
|
|
|
assert.deepEqual(actual, expected)
|
2017-09-11 18:11:45 -07:00
|
|
|
})
|
|
|
|
|
2018-08-01 09:16:02 -07:00
|
|
|
fixtures(__dirname, 'serialize', ({ module }) => {
|
|
|
|
const { input, output, rules, options } = module
|
|
|
|
const html = new Html({ rules, parseHtml: JSDOM.fragment })
|
|
|
|
const string = html.serialize(input, options)
|
|
|
|
const actual = string
|
|
|
|
const expected = output
|
|
|
|
assert.deepEqual(actual, expected)
|
2017-09-11 18:11:45 -07:00
|
|
|
})
|
|
|
|
})
|