-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix bug: decorate is not called for immediate children of editor #4394
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'slate-react': patch | ||
--- | ||
|
||
fix bug where decorate is not called on immediate children of editor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
describe('slate-react', () => {}) | ||
import * as Slate from 'slate' | ||
import * as SlateReact from '..' | ||
import { JSDOM } from 'jsdom' | ||
import React from 'react' | ||
import TestRenderer from 'react-test-renderer' | ||
import assert from 'assert' | ||
|
||
describe('slate-react', () => { | ||
describe('Editable', () => { | ||
describe('decorate', () => { | ||
// stub out some DOM stuff to avoid crashes | ||
before(() => { | ||
const jsdom = new JSDOM() | ||
global.window = jsdom.window | ||
global.document = jsdom.window.document | ||
global.Document = document.constructor | ||
}) | ||
|
||
const createNodeMock = () => ({ | ||
ownerDocument: global.document, | ||
getRootNode: () => global.document, | ||
}) | ||
|
||
it('should be called on all nodes in document', () => { | ||
const editor = SlateReact.withReact(Slate.createEditor()) | ||
const value = [{ type: 'block', children: [{ text: '' }] }] | ||
let count = 0 | ||
const decorate = ([node, path]) => { | ||
count++ | ||
return [] | ||
} | ||
|
||
const el = React.createElement( | ||
SlateReact.Slate, | ||
{ editor, value }, | ||
React.createElement(SlateReact.Editable, { decorate }) | ||
) | ||
|
||
TestRenderer.create(el, { createNodeMock }) | ||
|
||
// editor, block, text | ||
assert.strictEqual(count, 3) | ||
}) | ||
}) | ||
}) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent, we badly needed testing for |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too familiar with jsdom testing, but is there any way we could extract this global setting from this one suite, so it's done for all suites (when they exist)? Or must it be done a per-suite basis?
In fact, could you put the whole
decorate
test in adecorate.spec.ts
or similar file? Theindex
could just be common utilities among tests for example.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mostly use Jest which has special support for jsdom https://jestjs.io/docs/configuration#testenvironment-string. I didn't find an equivalent for Mocha but there is https://github.com/rstacruz/jsdom-global which does pretty much what I do here.
I think it could be done for the whole test file, but I didn't want to presume. I figured someone with more Mocha experience would have opinions about how to set things up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest we land this as it's an improvement all around, and then we can do a separate PR to look at extracting into a global setting.