UmiJS Jest Testing Utility

1.9.7 · abandoned · verified Sun Apr 19

The `umi-test` package (version 1.9.7) is a Jest-based utility designed to streamline testing configurations for UmiJS applications, primarily targeting UmiJS versions prior to v4. It provided pre-configured test framework setups and transformers, abstracting much of the boilerplate associated with Jest setup in a UmiJS environment. However, this specific package version was last published approximately four years ago (as of May 2022). For modern UmiJS v4 projects, the recommended approach for testing involves using `@umijs/preset-jest` in conjunction with Jest and `@testing-library/react`, or leveraging the integrated testing features of `@umijs/max`. Therefore, `umi-test` (v1.9.7) is considered largely superseded and no longer actively maintained, with a very slow or absent release cadence. Its key differentiator was simplifying Jest integration for older UmiJS projects, a role now filled by official presets and the `max` package for current UmiJS versions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic unit test for a React component within an UmiJS project, utilizing Jest and React Testing Library, which `umi-test` (or `@umijs/preset-jest` for Umi v4) would configure.

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

// Assuming you have a component like this in src/components/Greeting.tsx
const Greeting = ({ name = 'World' }) => <h1>Hello, {name}!</h1>;

describe('Greeting Component', () => {
  test('renders default greeting', () => {
    render(<Greeting />);
    expect(screen.getByText('Hello, World!')).toBeInTheDocument();
  });

  test('renders greeting with a specific name', () => {
    render(<Greeting name="Umi" />);
    expect(screen.getByText('Hello, Umi!')).toBeInTheDocument();
  });

  test('renders a snapshot correctly', () => {
    const { asFragment } = render(<Greeting name="Snapshot" />);
    expect(asFragment()).toMatchSnapshot();
  });
});

// To run this test, your package.json would typically have:
// {
//   "scripts": {
//     "test": "jest"
//   },
//   "jest": {
//     "preset": "@umijs/preset-jest" // Or earlier, configured by umi-test
//   }
// }

view raw JSON →