Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vitest-canvas-mock

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vitest-canvas-mock

🌗 A module used to mock canvas in Vitest.

  • 0.3.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
254K
increased by2.15%
Maintainers
1
Weekly downloads
 
Created

What is vitest-canvas-mock?

The vitest-canvas-mock npm package is a mock implementation of the HTMLCanvasElement for use with the Vitest testing framework. It allows developers to test canvas-related code without needing a real browser environment.

What are vitest-canvas-mock's main functionalities?

Mocking Canvas Methods

This feature allows you to mock canvas methods such as getContext, fillRect, and toDataURL. This is useful for testing drawing operations without needing a real canvas element.

const { createCanvas } = require('vitest-canvas-mock');
const canvas = createCanvas(200, 200);
const ctx = canvas.getContext('2d');
ctx.fillRect(50, 50, 100, 100);
console.log(canvas.toDataURL());

Mocking Canvas Properties

This feature allows you to mock canvas properties like width and height. This is useful for testing how your code interacts with canvas dimensions.

const { createCanvas } = require('vitest-canvas-mock');
const canvas = createCanvas(200, 200);
canvas.width = 300;
canvas.height = 300;
console.log(canvas.width, canvas.height);

Mocking Image Loading

This feature allows you to mock image loading, which is useful for testing code that relies on images being loaded into the canvas.

const { createImage } = require('vitest-canvas-mock');
const img = createImage();
img.src = 'data:image/png;base64,...';
img.onload = () => {
  console.log('Image loaded');
};

Other packages similar to vitest-canvas-mock

Keywords

FAQs

Package last updated on 09 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc