Is there a way to mock selecting of an editor's existing text within a test environment?
For example, I'd like select any text, then click a button that applies a link, in order to determine if the correct block type was applied.
I attempted manipulating the selectionState using Immutable's toJS and fromJS, but then lost functions available to selectionState.
Are there other methods by which I could manually set my selection?
I like to use Immutable's merge to update selection in tests. For example:
const selection = editorState.getSelection();
const newSelection = selection.merge({
anchorKey: someBlockKey,
anchorOffset: offsetInSomeBlock,
focusKey: someOtherBlockKey,
focusOffset: offsetInSomeOtherBlock
});
const newEditorState = EditorState.forceSelection(editorState, newSelection);
Does that seem like it might work better for you? Apologies if I misunderstood the question!
Yes, this seems like it will do it - thanks!
馃帀
Most helpful comment
Yes, this seems like it will do it - thanks!