skills/g2-unit-testing-skills/g2-testing/SKILL.md
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.
npx skillsauth add aiagentskills/skills G2 Unit Testing SkillsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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
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.
Before writing unit tests for G2, ensure you have:
G2 organizes tests into two main categories:
__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 testsdata/ - Data transformation testsscale/ - Scale related testsencode/ - Encoding related testscomponent/ - Component related testsutils/ - Utility function 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:
static/ - Static drawing related casesanimation/ - Animation related casesapi/ - Chart API related casesinteraction/ - Interaction related casestooltip/ - Tooltip related caseslegend/ - Legend related casesbugfix/ - Bug fix related casesFollow the standard Jest testing structure:
import { YourFunction } from '../../../src/your-module';
describe('YourFunction', () => {
it('should perform expected behavior', () => {
// Test implementation
expect(result).toBe(expected);
});
});
Integration tests typically export chart configurations:
import { G2Spec } from '../../../src';
export function alphabetInterval(): G2Spec {
return {
type: 'interval',
transform: [{ type: 'sortX', by: 'y', reverse: true }],
data: {
type: 'fetch',
value: 'data/alphabet.csv',
},
axis: {
y: { labelFormatter: '.0%' },
},
encode: {
x: 'letter',
y: 'frequency',
},
};
}
G2Specindex.ts file to make it visible in the preview environmentTo run all tests locally:
npm run test
To run tests on demand (specific test files or directories):
# Run specific test file
npm run test -- path/to/your/test-file.test.ts
# Run tests matching a pattern
npm run test -- --testNamePattern="legend"
This ensures your changes pass all existing tests before submitting a pull request.
Common issues and solutions:
documentation
Guides using bun.sys for system calls and file I/O in Zig. Use when implementing file operations instead of std.fs or std.posix.
development
Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas
development
Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas
development
Guides writing HMR/Dev Server tests in test/bake/. Use when creating or modifying dev server, hot reloading, or bundling tests.