Skip to content
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

Cannot find module 'ckeditor5' when testing with react-testing-library Next Js #517

Open
IrwanFicoFar opened this issue Aug 23, 2024 · 0 comments

Comments

@IrwanFicoFar
Copy link

IrwanFicoFar commented Aug 23, 2024

i have problem on my next js testing with ckeditor,

here is my ckeditor component :

'use client'

import { CKEditor } from '@ckeditor/ckeditor5-react'

import {
  ClassicEditor,
  Italic,
  Strikethrough,
  Subscript,
  Superscript,
  Underline,
  Heading,
  Highlight,
  Indent,
  IndentBlock,
  Link,
  Paragraph,
  SpecialCharacters,
  SpecialCharactersEssentials,
  TextTransformation,
} from 'ckeditor5'

import 'ckeditor5/ckeditor5.css'

import '../styles/textEditorNotification.css'

const TextEditorForNotification = ({ strData }: { strData?: string }) => {
  return (
    <CKEditor
      editor={ClassicEditor}
      disabled={true}
      config={{
        plugins: [
          Heading,
          Highlight,
          Indent,
          IndentBlock,
          Italic,
          Link,
          Paragraph,
          Strikethrough,
          SpecialCharacters,
          SpecialCharactersEssentials,
          Subscript,
          Superscript,
          TextTransformation,
          Underline,
        ],
      }}
      data={strData}
    />
  )
}

export default TextEditorForNotification

and this is my testing :

import React from 'react'
import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'

jest.mock('@ckeditor/ckeditor5-react', () => ({
  CKEditor: ({ data }: { data: string }) => <div data-testid="mock-ckeditor">{data}</div>,
}))

import TextEditorForNotification from '../src/components/textEditorForNotification'

describe('TextEditorForNotification', () => {
  it('renders CKEditor with correct data', () => {
    const testData = '<p>Test content</p>'
    render(<TextEditorForNotification strData={testData} />)

    const mockEditor = screen.getByTestId('mock-ckeditor')
    expect(mockEditor).toHaveTextContent('Test content')
  })

  it('renders CKEditor with empty data', () => {
    render(<TextEditorForNotification />)

    const mockEditor = screen.getByTestId('mock-ckeditor')
    expect(mockEditor).toBeNull()
  })
})

error is :
gambar

i dont know why not found, becuase depencies is already exist, this only error in testing actually..

detail :

  • "next": "14.1.1",
  • "@ckeditor/ckeditor5-react": "^9.0.0",
  • "ckeditor5": "^42.0.2"
  • "@testing-library/react": "^16.0.0"
  • "jest": "^29.6.2"
  • npm version : 8.19.4
  • node verison : 21.1.0
  • os version : windows 11
@IrwanFicoFar IrwanFicoFar changed the title Cannot find module 'ckeditor5' when testing with react-testing-library jest Cannot find module 'ckeditor5' when testing with react-testing-library Aug 24, 2024
@IrwanFicoFar IrwanFicoFar changed the title Cannot find module 'ckeditor5' when testing with react-testing-library Cannot find module 'ckeditor5' when testing with react-testing-library Next Js Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant