Skip to content

Ckeditors are rendered as hidden during tests when testing with react testing libraries #305

@M-Ravilal

Description

@M-Ravilal

I am getting the ckeditor rendered as hidden during tests using react testing library. Here is the sample code of the component and test structure
Component setup:

<RichTextEditor
name='choice'
onChange={(event) => choiceChange(event)}
onReady={(editor) => {
setChoiceEditor(editor);
choiceEditorRef.current = editor;
}}
initData={choice}
readOnly={editData?.InUse}
/>

Test setup:
let isEdit = true;
const isTranslateActionType = false;
const renderMultipleChoiceScreen = async () =>
waitFor(() =>
expect(() => {
render(

);
}).not.toThrowError()
);

describe('MultipleChoice', () => {
afterEach(cleanup);

it('should render with all fields in Edit Mode, Select Line', async ()
=> {
await renderMultipleChoiceScreen();

const btnSelect = document.getElementById('select-question');
expect(btnSelect).toBeInTheDocument();
userEvent.click(btnSelect);

const btnReset = document.getElementById('reset');
expect(btnReset).toBeInTheDocument();
userEvent.click(btnReset);

userEvent.click(btnSelect);

const btnUpdate = document.getElementById('update');
expect(btnUpdate).toBeInTheDocument();
expect(btnUpdate).toBeDisabled();

});

tried this way
// CKEDITORS - renders as hidden during tests
expect( document.querySelectorAll('div[style*="display: none"]').length ).toBe(4); expect( document.querySelectorAll('div[style*="visibility: hidden"]').length ).toBe(4);

this works but unable to set the value and test the updated value

  • CKEditor version: 3.1.0
  • Installed CKEditor plugins: ckeditor4-react

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions