Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-remirror

Package Overview
Dependencies
Maintainers
0
Versions
353
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-remirror

A text editor for react built with prosemirror

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
increased by150.94%
Maintainers
0
Weekly downloads
 
Created
Source

jest-remirror

npm

Installation

yarn add jest-remirror # yarn
pnpm add jest-remirror # pnpm
npm install jest-remirror # npm

Getting started

Quick setup

For a quick setup add the following to your jest.config.js file.

/* jest.config.js */

module.exports = {
  setupFilesAfterEnv: ['jest-remirror/environment'],
  testEnvironment: 'jsdom', // Required for dom manipulation
};

This will automatically

  • inject the required JSDOM polyfills
  • Add the jest assertions toEqualRemirrorDocument and toMatchRemirrorSnapshot.

If you are using typescript then add this to your tsconfig.json file for global type support.

{
  "compilerOptions": {
    "types": ["jest-remirror"]
  }
}

Manual setup

Create a jest.framework.dom.ts file and add the following

/* jest.framework.dom.ts */

import { jsdomPolyfill, remirrorMatchers } from 'jest-remirror';

/* Add jest-remirror assertions */
expect.extend(remirrorMatchers);

/* Polyfills for jsdom */
jsdomPolyfill();

In your jest.config.js file add this to the configuration

/* jest.config.js */

module.exports = {
  setupFilesAfterEnv: ['<rootDir>/jest.framework.dom.ts'],
  testEnvironment: 'jsdom', // Required for dom manipulation
};

The problem

Testing contenteditable is really difficult, especially with jsdom. There are certain events that can't be fired and it's often hard to conceptualize how the test result translates to the actual user experience.

A solution

jest-remirror makes rendering the remirror editor painless so that you can test that your extensions:

  • have the intended effect on the HTML output
  • call the correct callbacks

Under the hood jest-remirror leans heavily on @remirror/dom to render an instance of your test editor to the dom and provides a number of utilities exposed when calling the renderEditor method.

Example

import { renderEditor } from 'jest-remirror';
import { EmojiExtension } from '@remirror/extension-emoji';

test('emoticons replaced with emoji', () => {
  const {
    nodes: { p, doc },
    add,
  } = renderEditor({ plainNodes: [], others: [new EmojiExtension()] });

  add(doc(p('<cursor>')))
    .insertText(':-)')
    .callback((content) => {
      expect(content.state.doc).toEqualRemirrorDocument(doc(p('😃')));
    });
});

Acknowledgements

This package borrows very heavily from @atlaskit/editor-test-helpers

Keywords

FAQs

Package last updated on 01 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc