1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-03-08 23:09:47 +01:00
Jinxuan Zhu 58c644323f Add coverage test with mocha and codecov (#2037)
* Run mocha test with module alias

* Running test with babel module alias

* Fix model alias

* Fix model alias

* Resolve module alias

* Running test with babel module alias

* Connect to codecov

* add codecov to travis

* stop if yarn test has errors

* Still cannot collect data from slate modules

* Try to check whether it works with codecov

* Move config to nycrc

* Remove nyc require

* Update nyc to use src

* better before_script
2018-08-06 10:31:42 -07:00

43 lines
1.3 KiB
JavaScript

import AfterPlugin from '../src/plugins/after'
import assert from 'assert'
import BeforePlugin from '../src/plugins/before'
import clean from './helpers/clean'
import React from 'react'
import ReactDOM from 'react-dom/server'
import Simulator from 'slate-simulator'
import { Editor } from 'slate-react'
import { fixtures } from 'slate-dev-test-utils'
import { JSDOM } from 'jsdom'
describe('slate-react', () => {
fixtures.skip(__dirname, 'plugins', ({ module }) => {
const { input, output, props = {} } = module
const fn = module.default
const plugins = [BeforePlugin(props), AfterPlugin(props)]
const simulator = new Simulator({ plugins, value: input })
fn(simulator)
const actual = simulator.value.toJSON({ preserveSelection: true })
const expected = output.toJSON({ preserveSelection: true })
assert.deepEqual(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)
})
})