Skip to content

Instantly share code, notes, and snippets.

@esmevane
Created August 15, 2017 11:26
Show Gist options
  • Select an option

  • Save esmevane/55b42fdb0a31bfca37cacae579a62e38 to your computer and use it in GitHub Desktop.

Select an option

Save esmevane/55b42fdb0a31bfca37cacae579a62e38 to your computer and use it in GitHub Desktop.
[ Typescript / Javascript / Chai / Draftjs ]: Wouldn't it be nice if there were Draft.js chai helpers?
import chai, { expect } from 'chai'
import { EditorState } from 'draft-js'
expect(editorState).to.have.content(contentState)
expect(contentState).to.eql.content(otherState)
expect(editorState).to.have.block(contentBlock)
expect(contentState).to.have.block(contentBlock)
expect(editorState).to.contain.text('Contents')
expect(contentState).to.contain.text('Contents')
expect(contentBlock).to.contain.text('Contents')
expect(editorState).to.startWith('#')
expect(contentState).to.startWith('#')
expect(contentBlock).to.startWith('#')
expect(editorState).to.have.types(
'header-one',
'header-two',
'unstyled',
'unordered-list'
)
expect(contentState).to.have.types(
'header-one',
'header-two',
'unstyled',
'unordered-list'
)
expect(contentBlock).to.have.type('header-one')
expect(editorState).to.have.selectedText('Some stuff')
expect(contentState).to.have.selectedText('Some stuff')
expect(contentBlock).to.have.selectedText('Some stuff')
expect(editorState).to.style('stuff').with('bold')
expect(contentState).to.style('stuff').with('bold')
expect(contentBlock).to.style('stuff').with('bold')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment