UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

46 lines 1.64 kB
import React from "react"; import { render, screen } from "@testing-library/react"; import "@testing-library/jest-dom"; import ChartContext from "./context"; import { jsx as _jsx } from "react/jsx-runtime"; describe("ChartContext", function () { it("creates React context with null default value", function () { expect(ChartContext).toBeDefined(); expect(ChartContext.Provider).toBeDefined(); expect(ChartContext.Consumer).toBeDefined(); }); it("provides context value to children", function () { var testValue = { test: "data" }; var TestComponent = function TestComponent() { return /*#__PURE__*/_jsx(ChartContext.Consumer, { children: function children(value) { return /*#__PURE__*/_jsx("div", { "data-testid": "context-value", children: JSON.stringify(value) }); } }); }; render(/*#__PURE__*/_jsx(ChartContext.Provider, { value: testValue, children: /*#__PURE__*/_jsx(TestComponent, {}) })); expect(screen.getByTestId("context-value")).toHaveTextContent('{"test":"data"}'); }); it("provides null by default when no provider", function () { var TestComponent = function TestComponent() { return /*#__PURE__*/_jsx(ChartContext.Consumer, { children: function children(value) { return /*#__PURE__*/_jsx("div", { "data-testid": "context-value", children: String(value) }); } }); }; render(/*#__PURE__*/_jsx(TestComponent, {})); expect(screen.getByTestId("context-value")).toHaveTextContent("null"); }); });