Encountering an issue with testing CKEditor in Jest

Testing my project configured with vite (Typescript) and using jest showed an error related to ckeditor. The error is displayed as follows: [![enter image description here][1]][1]

The contents of package.json:

{
  "name": "test-project",
  ...
}

The contents of jest.config.ts:

import { pathsToModuleNameMapper, JestConfigWithTsJest } from 'ts-jest';
...
};

export default jestConfig;

The contents of tsconfig.json:

{
  "compilerOptions": {
    ...
  },
  ...
}

I have attempted various solutions found online but I am unable to identify the root cause of the issue. How can I resolve this problem? [1]: https://i.sstatic.net/ozhF1.png

Answer №1

Just encountered this issue today

To resolve the problem in your code, make sure to include @ckeditor in the list of elements not to be ignored. The full path, including node modules, is required rather than just a single string.

transformIgnorePatterns: ["node_modules\\/\\.pnpm\\/(?!(@ckeditor))"

By utilizing the above line, all node modules will be checked except for @ckeditor (you may also need to ignore additional packages like lodash, which could be used by @ckeditor)

Since we are no longer ignoring this module, instructions on how to compile them should be provided.

transform: {  [`node_modules\\/\\.pnpm\\/${includePatterns}`]: 'babel-jest' }

Key points to note:

  • The use of \\ to escape the / is crucial
  • If you are not using pnpm, remove the part \\/\\.pnpm
  • In the case of TypeScript usage, adding a transform for ts files may be necessary after updating the ignore configuration
const includePatterns = [
    '@ckeditor',
    'ckeditor',
    'lodash',
    'vanilla-colorful',
].join('|');

module.exports = {
    setupFiles: ['<rootDir>/tests/lib/set-up.ts'],
    testEnvironment: 'node',
    transform: {
      '^.+\\.(tsx?|ts)$': 'ts-jest',
      [`node_modules\\/\\.pnpm\\/${includePatterns}`]: 'babel-jest',
    },
    transformIgnorePatterns: [
      `node_modules\\/\\.pnpm\\/(?!(${includePatterns}))`,
    ],
    moduleNameMapper: {
      '.*\\.(css|png|svg)$': '<rootDir>/tests/lib/dummy.ts',
    },
};

After following these steps, I managed to get it working. However, to properly test ClassicEditor, I had to utilize jsdom in order to simulate certain aspects (my tests were conducted in node mode).

global.window.ResizeObserver = jest.fn().mockImplementation(() => ({
    observe: jest.fn(),
    unobserve: jest.fn(),
    disconnect: jest.fn(),
}));
global.document = jsdom.window.document;
global.HTMLElement = jsdom.window.HTMLElement;
global.HTMLTextAreaElement = jsdom.window.HTMLTextAreaElement;
global.MutationObserver = jsdom.window.MutationObserver;
global.DOMParser = jsdom.window.DOMParser;
global.Node = jsdom.window.Node;

The compilation and functionality are now successful, with ongoing progress towards data insertion and DOM manipulation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Errors during TypeScript compilation in Twilio Functions

When I run npx tsc, I encounter the following errors: node_modules/@twilio-labs/serverless-runtime-types/types.d.ts:5:10 - error TS2305: Module '"twilio/lib/rest/Twilio"' does not export 'TwilioClientOptions'. 5 import { Twil ...

Issues with navigation in React Native Typescript

Currently, I am in the process of developing a new React Native Expo project utilizing TypeScript. I have been attempting to configure navigation following the guidance provided in React Native's TypeScript documentation. However, upon running and sim ...

The TypeScript function was anticipating one argument, however it received two instead

Can you help me fix the issue with my createUser() function? Why am I unable to pass parameters in Smoke.ts? Login.ts : interface User { url: string, email: string, } class Test{ async createUser(user: User) { await Page.setUrl(user.url); aw ...

Issue in Angular: Attempting to access properties of undefined (specifically 'CustomHeaderComponent')

I have encountered a persistent error message while working on a new component for my project. Despite double-checking the injection code and ensuring that the module and component export logic are correct, I am unable to pinpoint the issue. custom-header ...

What methods can be used to accurately display the data type with TypeOf()?

When working with the following code: const data = Observable.from([{name: 'Alice', age: 25}, {name: 'Bob', age: 35}]); console.log(typeof(data)); The type is displayed as Object(). Is there a way to obtain more specific information? ...

Is there a beginner's pack or trial version available for utilizing TypeScript with IBM Cloud Functions / OpenWhisk?

While working on developing actions in IBM Cloud Functions, I have been primarily using Node.js / Javascript and Python for coding. However, I haven't come across specific instructions on how to incorporate TypeScript into IBM Cloud Functions. I am c ...

React-table fails to show newly updated data

I am facing an issue with my react-table where real-time notifications received from an event-source are not being reflected in the table after data refresh. https://i.stack.imgur.com/q4vLL.png The first screenshot shows the initial data retrieval from th ...

Managing conflicting versions of React in a component library created with Webpack and Storybook

My goal is to create a React component library on top of MUI using Storybook and TypeScript. Since Storybook is based on Webpack (which includes SASS files), I'm utilizing Webpack to build the bundle because TSC can't compile those files. Subsequ ...

A step-by-step guide to showcasing dates in HTML with Angular

I have set up two datepickers in my HTML file using bootstrap and I am attempting to display a message that shows the period between the first selected date and the second selected date. The typescript class is as follows: export class Datepicker { ...

Jest - experiencing intermittent test failures on initial run, yet succeeding on subsequent runs

Writing tests with jest and supertest npm on a node server has been a challenge for me. When I try to run all the tests together, some of them fail inexplicably: https://i.sstatic.net/TWDVp.png However, if I selectively run only the failed tests in the t ...

Guide on navigating to a specific step within a wizard using Vue and TypeScript

In this wizard, there are 6 steps. The last step includes a button that redirects the user back to step 4 when clicked. The user must then complete steps 5 and 6 in order to finish the wizard. step6.ts <router-link to="/stepFour" ...

What is the best way to strip out a changing segment of text from a string?

let: string str = "a=<random text> a=pattern:<random text (may be fixed length)> a=<random text>"; In the given string above, let's assume that a= and pattern are constants. It is possible that there may or may not be a ...

Encountered an issue with ionViewDidLoad: The property 'firstChild' cannot be read as it is null

While working on an Ionic 2 App with Angular2 and Typescript, I encountered an issue when trying to pass a JSON to map for markers. Here is the link to the gist containing the code snippet I am facing an error that reads: view-controller.js:231 MapPage i ...

Strange occurrences observed in the functionality of Angular Material Version 16

Encountered a strange bug recently. Whenever the page height exceeds the viewport due to mat-form-fields, I'm facing an issue where some elements, particularly those from Angular Material, fail to load. Here's a GIF demonstrating the problem: GI ...

Tips for splitting JSON objects into individual arrays in React

I'm currently tackling a project that requires me to extract 2 JSON objects into separate arrays for use within the application. I want this process to be dynamic, as there may be varying numbers of objects inside the JSON array in the future - potent ...

React Redux Saga doesn't trigger any actions

Currently, I am attempting to incorporate the following functionality: Users can successfully log in, but precisely after 5 seconds have passed, they are automatically logged out. My approach involves working with JSONWEBTOKEN. Here is my implementation u ...

Challenges with Type Casting in TypeScript

Upon reviewing a specific piece of code, I noticed that it is not producing any compile time or run time errors even though it should: message: string // this variable is of type string -- Line 1 <br> abc: somedatatype // lets assume abc is of some ...

TypeScript error message: "The 'new' keyword cannot be used with an expression that does not have a call or construct signature."

Encountered a problem with intersection types in TypeScript... There are three type aliases: Prototype<T> - representing an object or class with a prototype property. DefaultCtor<T> - representing an object or class with a default construct ...

Can a self-referential type truly exist?

There is a function that takes in a configuration object containing color definitions. For example: useColors({ colors: { RED: { hex: 0xff0000 }, GREEN: { hex: 0x00ff00 }, BLUE: { hex: 0x0000ff } }, doSomethingWithColor(getColor) { g ...

What is the best way to dynamically insert content into a PDF using pdfmake?

In my quest to dynamically generate PDFs using pdfmake, I've encountered an issue with creating dynamic rows based on data. To illustrate, here is a simplified version of the code: getDocumentDefinition(img: string, data: DataResponse, user: UserResp ...