Guidelines and best practices for writing unit tests in the G2 visualization library, covering directory structure, testing patterns, and implementation guidelines. Use when need to generate test.
>_
Quick Install
npxskills add antvis/g2--skill "G2 Unit Testing Skills"
Instructions
Loading…
Tags & Topics
visualizationgrammargraphicscanvassvginteraction
Document Information
Document Title: G2 Unit Testing Skill Specification
Version: 1.0
Author: G2 Development Team
Purpose: Guide for writing effective unit tests in the G2 visualization library
Overview
This skill specification provides comprehensive guidelines for writing unit tests in the G2 visualization library. It covers directory structure, testing patterns, best practices, and implementation guidelines to ensure consistent and maintainable test code.
Prerequisites
Before writing unit tests for G2, ensure you have:
Understanding of TypeScript and Jest testing framework
Familiarity with G2's codebase structure
Knowledge of the specific module you are testing
Test Directory Structure
G2 organizes tests into two main categories:
Unit Tests (__tests__/unit/)
Unit tests are for testing pure data modules or functions. They are located in __tests__/unit/ and organized by module:
api/ - Chart API related tests
data/ - Data transformation tests
- Scale related tests
scale/
encode/ - Encoding related tests
component/ - Component related tests
utils/ - Utility function tests
And more...
Integration Tests (__tests__/plots/)
Integration tests test the rendering results of the entire visualization chart by comparing screenshots. Located in __tests__/plots/, these are organized by focus areas: