Wondering what’s next for npm?Check out our public roadmap! »

@zeromake/jest-environment-jsdom-with-canvas

0.1.1 • Public • Published

jest-environment-jsdom-with-canvas

Jest environment with jsdom v13 and node-canvas v2

why I created this

So, in short, if we want to use node-canvas v2.x with Jest, we cannot rely on the official environment (i.e., jsdom defined at packages/jest-environment-jsdom).

This repository provides a Jest environment with the latest jsdom and node-canvas as of January, 2019.

how to use

For a more detailed usage example, see another repository that uses CreateJS/EaselJS for canvas manipulation.

  1. install this package along with Jest
$ npm i -D jest
$ npm i -D https://github.com/arcatdmz/jest-environment-jsdom-with-canvas.git
  1. create jest.config.js so that Jest uses jest-environment-jsdom-with-canvas
module.exports = {
  testEnvironment: "jest-environment-jsdom-with-canvas"
};
  1. write tests (e.g., ./__tests__/canvas.js)
describe("canvas", () => {
  let canvas = document.createElement("canvas");
  test("get context", () => {
    let ctx = null;
    try {
      ctx = canvas.getContext("2d")
    } catch (e) {}
    expect(ctx).not.toBeNull();
  });
});

links


https://github.com/arcatdmz/jest-environment-jsdom-with-canvas

Keywords

none

Install

npm i @zeromake/jest-environment-jsdom-with-canvas

DownloadsWeekly Downloads

2

Version

0.1.1

License

MIT

Unpacked Size

5.99 kB

Total Files

3

Last publish

Collaborators

  • avatar