TheSunny
doc-ios
doc-ios
  • Introduction
  • Walkthroughs
    • Installing Slate
    • Adding Event Handlers
    • Defining Custom Block Nodes
    • Applying Custom Formatting
    • Using Plugins
    • Saving to a Database
    • Saving and Loading HTML Content
  • Guides
    • Changes
    • Data Model
    • Plugins
    • Rendering
    • Schemas
  • General
    • Plugins
    • Resources
    • Contributing
    • Changelog
    • FAQ
  • Slate Core
    • Block
    • Change
    • Character
    • Data
    • Document
    • Inline
    • Mark
    • Node
    • Operation
    • Range
    • Schema
    • Text
    • Value
    • setKeyGenerator
    • resetKeyGenerator
  • Slate React
    • Editor
    • Plugins
    • Custom Nodes
    • Core Plugins
    • cloneFragment
    • findDOMNode
    • findDOMRange
    • findNode
    • findRange
    • getEventRange
    • getEventTransfer
    • setEventTransfer
  • Other Packages
    • slate-html-serializer
    • slate-hyperscript
    • slate-plain-serializer
    • slate-prop-types
    • slate-schema-violations
    • slate-simulator
  • Contributing
    • iOS Development Guide
Powered by GitBook
On this page
  • Example
  • Example with core plugins
  • Methods
  • beforeInput
  • blur
  • copy
  • cut
  • drop
  • focus
  • keyDown
  • select
  1. Other Packages

slate-simulator

import Simulator from 'slate-simulator'

A simulator to help writing tests for Slate editors and plugins. By default the simulator does not include the core plugins as they have a lot of dependencies on browser-specific globals, so running them in CI environments is very hard. If you need the core plugins for your use case you need to import them manually.

Example

import Simulator from 'slate-simulator'

const value = ...
const plugins = [ ... ]
const simulator = new Simulator({ value, plugins })

simulator
  .focus()
  .beforeInput({ data: 'H' })
  .beforeInput({ data: 'e' })
  .beforeInput({ data: 'l' })
  .beforeInput({ data: 'l' })
  .beforeInput({ data: 'o' })
  .beforeInput({ data: '!' })
  .keyDown({ key: 'Enter' })

const newValue = simulator.value

Example with core plugins

import Simulator from 'slate-simulator'
import { BeforePlugin, AfterPlugin } from 'slate-react'

const value = ...
const plugins = [ BeforePlugin(), ... , AfterPlugin() ]
const simulator = new Simulator({ value, plugins })

Methods

beforeInput

beforeInput(event: Object) => Simulator

Simulator a beforeinput event with an event object.

blur

blur(event: Object) => Simulator

Simulator a blur event with an event object.

copy

copy(event: Object) => Simulator

Simulator a copy event with an event object.

cut

cut(event: Object) => Simulator

Simulator a cut event with an event object.

drop

drop(event: Object) => Simulator

Simulator a drop event with an event object.

focus

focus(event: Object) => Simulator

Simulator a focus event with an event object.

keyDown

keyDown(event: Object) => Simulator

Simulator a keyDown event with an event object.

select

select(event: Object) => Simulator

Simulator a select event with an event object.

Previousslate-schema-violationsNextiOS Development Guide

Last updated 7 years ago