415 |
416 |
417 |
418 |
419 |
420 |
421 | {preset({ onInit, decorateOptions })}
422 |
423 | );
424 | };
425 |
--------------------------------------------------------------------------------
/tests/index.spec.tsx:
--------------------------------------------------------------------------------
1 | import * as React from "react";
2 | import { render, screen } from "@testing-library/react";
3 | import * as canvasConfetti from "canvas-confetti";
4 | import ReactCanvasConfetti from "../src";
5 | import Preset from "../src/presets";
6 | import Conductor from "../src/conductor";
7 | import FireworksConductor from "../src/conductor/fireworks";
8 |
9 | const getCanvasElement = () =>
10 | screen.getByText((_, element) => element?.tagName.toLowerCase() === "canvas");
11 |
12 | const decorateOptions = jest.fn();
13 | const conductorInstance = { run: jest.fn() };
14 |
15 | jest.mock("canvas-confetti");
16 | jest.mock("../src/conductor", () =>
17 | jest.fn().mockImplementation(() => conductorInstance),
18 | );
19 |
20 | beforeEach(() => {
21 | (canvasConfetti.create as jest.Mock).mockClear();
22 | decorateOptions.mockClear();
23 | conductorInstance.run.mockClear();
24 | });
25 | describe("Component", () => {
26 | describe("Init", () => {
27 | it("should render canvas", () => {
28 | render(