Skip to content

charton API


charton API / @chart-on/core / testing / installTestEnvironment

Function: installTestEnvironment() ​

installTestEnvironment(options?): TestEnvironment

Defined in: packages/core/src/testing/kit.ts:51

Install just enough DOM, Canvas2D and WebGL2 for a chart to run under Node, without a browser or GPU. Drawing calls do nothing; layout, data, scales, events and the frame loop work as in a browser. Frames run only through driveFrames or flushFrames. Use it in a Node test environment, not a DOM one (jsdom, happy-dom): it replaces document and window outright.

Parameters ​

options? ​

TestEnvironmentOptions = {}

Returns ​

TestEnvironment

Example ​

ts
import { createChart } from '@chart-on/core';
import { describeScene, flushFrames, installTestEnvironment, sampleBars } from '@chart-on/core/testing';

const env = installTestEnvironment({ width: 960, height: 540 });
const chart = createChart(env.container());
chart.addCandles().setData(sampleBars({ count: 300, seed: 1 }));
flushFrames();
expect(describeScene(chart)).toMatchSnapshot();
chart.destroy();
env.uninstall();