Repository: hustcc/jest-canvas-mock
Pull request #100 (2022-08-18 16:00:27)

Pass window object to mockPrototype
When mocking the canvas on a non-global window object, the prototype
mocks should apply to the same window object.

hustcc: Can it work? do your have tested it?
jdufresne: @hustcc I added a test case in the latest revision. Is this what you had in mind?

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6e1e539..0fc817a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
 # CHANGELOG
 
+## Version 2.5.0
+
+- feat: export a function to re-initialize mocks (#98)
+- docs: fix some typos (#104)
+- fix: copy & paste mistake: toBlob -> toDataURL (#101)
+- chore: add Contributors LitoMore (#94)
+
 ## Version 2.4.0
 
 - fix(window): avoid global.window redefinition (#91)
diff --git a/README.md b/README.md
index 1f935c5..58820da 100644
--- a/README.md
+++ b/README.md
@@ -195,6 +195,8 @@ canvas.toDataURL.mockReturnValueOnce(
 - [@lekha](https://github.com/lekha)
 - [@yonatankra](https://github.com/yonatankra)
 - [@LitoMore](https://github.com/LitoMore)
+- [@hrd543](https://github.com/hrd543)
+- [@danielrentz](https://github.com/danielrentz)
 
 ## License
 
diff --git a/package.json b/package.json
index bf5973f..9200c5d 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "jest-canvas-mock",
-  "version": "2.4.0",
+  "version": "2.5.0",
   "description": "Mock a canvas in your jest tests.",
   "main": "lib/index.js",
   "types": "types/index.d.ts",
diff --git a/src/classes/CanvasGradient.js b/src/classes/CanvasGradient.js
index 6685e88..b6edb97 100644
--- a/src/classes/CanvasGradient.js
+++ b/src/classes/CanvasGradient.js
@@ -9,10 +9,10 @@ export default class CanvasGradient {
     const numoffset = Number(offset);
     if (!Number.isFinite(numoffset) || numoffset < 0 || numoffset > 1) {
       throw new DOMException(
-        'IndexSizeError',
         "Failed to execute 'addColorStop' on 'CanvasGradient': The provided value ('" +
           numoffset +
-          "') is outside the range (0.0, 1.0)"
+          "') is outside the range (0.0, 1.0)",
+        'IndexSizeError'
       );
     }
     try {
diff --git a/src/classes/CanvasRenderingContext2D.js b/src/classes/CanvasRenderingContext2D.js
index 477d245..c4800b3 100644
--- a/src/classes/CanvasRenderingContext2D.js
+++ b/src/classes/CanvasRenderingContext2D.js
@@ -188,10 +188,10 @@ export default class CanvasRenderingContext2D {
       options;
     if (!path && !id)
       throw new DOMException(
-        'ConstraintError',
         "Failed to execute 'addHitRegion' on '" +
           this.constructor.name +
-          "': Both id and control are null."
+          "': Both id and control are null.",
+        'ConstraintError'
       );
     if (fillRule && fillRule !== 'evenodd' && fillRule !== 'nonzero')
       throw new TypeError(
@@ -242,12 +242,12 @@ export default class CanvasRenderingContext2D {
 
     if (Number(radius) < 0)
       throw new DOMException(
-        'IndexSizeError',
         "Failed to execute 'arc' on '" +
           this.constructor.name +
           "': The radius provided (" +
           radius +
-          ') is negative.'
+          ') is negative.',
+        'IndexSizeError'
       );
 
     const event = createCanvasEvent('arc', getTransformSlice(this), {
@@ -264,8 +264,7 @@ export default class CanvasRenderingContext2D {
 
   arcTo(cpx1, cpy1, cpx2, cpy2, radius) {
     if (arguments.length < 5)
-      throw new DOMException(
-        'IndexSizeError',
+      throw new TypeError(
         "Failed to execute 'arcTo' on '" +
           this.constructor.name +
           "': 5 arguments required, but only " +
@@ -285,12 +284,13 @@ export default class CanvasRenderingContext2D {
     )
       return;
     if (radiusResult < 0)
-      throw new TypeError(
+      throw new DOMException(
         "Failed to execute 'arcTo' on '" +
           this.constructor.name +
           "': The radius provided (" +
           radius +
-          ') is negative.'
+          ') is negative.',
+        'IndexSizeError'
       );
 
     const event = createCanvasEvent('arcTo', getTransformSlice(this), {
@@ -553,8 +553,8 @@ export default class CanvasRenderingContext2D {
       if (image instanceof ImageBitmap) {
         if (image._closed)
           throw new DOMException(
-            'InvalidStateError',
-            "Failed to execute 'createPattern' on 'CanvasRenderingContext2D': The image source is detached."
+            "Failed to execute 'createPattern' on 'CanvasRenderingContext2D': The image source is detached.",
+            'InvalidStateError'
           );
         this._events.push(event);
         return new CanvasPattern();
@@ -616,17 +616,17 @@ export default class CanvasRenderingContext2D {
       );
     if (r0Result < 0)
       throw new DOMException(
-        'IndexSizeError',
         "Failed to execute 'createRadialGradient' on '" +
           this.constructor.name +
-          "': The r0 provided is less than 0."
+          "': The r0 provided is less than 0.",
+        'IndexSizeError'
       );
     if (r1Result < 0)
       throw new DOMException(
-        'IndexSizeError',
         "Failed to execute 'createRadialGradient' on '" +
           this.constructor.name +
-          "': The r1 provided is less than 0."
+          "': The r1 provided is less than 0.",
+        'IndexSizeError'
       );
 
     const event = createCanvasEvent(
@@ -746,8 +746,8 @@ export default class CanvasRenderingContext2D {
     if (img instanceof ImageBitmap) {
       if (img._closed)
         throw new DOMException(
-          'InvalidStateError',
-          "DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image source is detached."
+          "DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image source is detached.",
+          'InvalidStateError'
         );
       valid = true;
     }
@@ -864,21 +864,21 @@ export default class CanvasRenderingContext2D {
 
     if (Number(radiusX) < 0)
       throw new DOMException(
-        'IndexSizeError',
         "Failed to execute 'ellipse' on '" +
           this.constructor.name +
           "': The major-axis radius provided (" +
           radiusX +
-          ') is negative.'
+          ') is negative.',
+        'IndexSizeError'
       );
     if (Number(radiusY) < 0)
       throw new DOMException(
-        'IndexSizeError',
         "Failed to execute 'ellipse' on '" +
           this.constructor.name +
           "': The minor-axis radius provided (" +
           radiusY +
-          ') is negative.'
+          ') is negative.',
+        'IndexSizeError'
       );
 
     const event = createCanvasEvent('ellipse', getTransformSlice(this), {
@@ -1053,8 +1053,25 @@ export default class CanvasRenderingContext2D {
     return this._fontStack[this._stackIndex];
   }
 
-  getImageData() {
-    return new ImageData(this._canvas.width, this._canvas.height);
+  getImageData(x, y, w, h) {
+    if (arguments.length < 4)
+      throw new TypeError(
+        "Failed to execute 'getImageData' on '" +
+          this.constructor.name +
+          "': 4 arguments required, but only " +
+          arguments.length +
+          ' present.'
+      );
+    if (w == 0 || h == 0)
+      throw new DOMException(
+        "Failed to execute 'getImageData' on '" +
+          this.constructor.name +
+          "': The source " +
+          (w == 0 ? 'width' : 'height') +
+          ' is 0.',
+        'IndexSizeError'
+      );
+    return new ImageData(Math.abs(w), Math.abs(h));
   }
 
   getLineDash() {
diff --git a/src/mock/prototype.js b/src/mock/prototype.js
index 0a733a7..3983654 100644
--- a/src/mock/prototype.js
+++ b/src/mock/prototype.js
@@ -1,4 +1,4 @@
-export default function mockPrototype() {
+export default function mockPrototype(win) {
   /**
    * This weakmap is designed to contain all of the generated canvas contexts. It's keys are the
    * jsdom canvases obtained by using the `this` keyword inside the `#getContext('2d')` function
@@ -29,12 +29,12 @@ export default function mockPrototype() {
     return getContext2D.internal.call(this, type);
   });
 
-  if (!jest.isMockFunction(HTMLCanvasElement.prototype.getContext)) {
-    getContext2D.internal = HTMLCanvasElement.prototype.getContext;
+  if (!jest.isMockFunction(win.HTMLCanvasElement.prototype.getContext)) {
+    getContext2D.internal = win.HTMLCanvasElement.prototype.getContext;
   } else {
-    getContext2D.internal = HTMLCanvasElement.prototype.getContext.internal;
+    getContext2D.internal = win.HTMLCanvasElement.prototype.getContext.internal;
   }
-  HTMLCanvasElement.prototype.getContext = getContext2D;
+  win.HTMLCanvasElement.prototype.getContext = getContext2D;
 
   /**
    * This function technically throws SecurityError at runtime, but it cannot be mocked, because
@@ -73,12 +73,12 @@ export default function mockPrototype() {
     setTimeout(() => callback(blob), 0);
   });
 
-  if (!jest.isMockFunction(HTMLCanvasElement.prototype.toBlob)) {
-    toBlobOverride.internal = HTMLCanvasElement.prototype.toBlob;
+  if (!jest.isMockFunction(win.HTMLCanvasElement.prototype.toBlob)) {
+    toBlobOverride.internal = win.HTMLCanvasElement.prototype.toBlob;
   } else {
-    toBlobOverride.internal = HTMLCanvasElement.prototype.toBlob.internal;
+    toBlobOverride.internal = win.HTMLCanvasElement.prototype.toBlob.internal;
   }
-  HTMLCanvasElement.prototype.toBlob = toBlobOverride;
+  win.HTMLCanvasElement.prototype.toBlob = toBlobOverride;
 
   /**
    * This section creates a dataurl with a validated mime type. This is not actually valid, because
@@ -103,10 +103,11 @@ export default function mockPrototype() {
     return 'data:' + type + ';base64,00';
   });
 
-  if (!jest.isMockFunction(HTMLCanvasElement.prototype.toDataURL)) {
-    toDataURLOverride.internal = HTMLCanvasElement.prototype.toDataURL;
+  if (!jest.isMockFunction(win.HTMLCanvasElement.prototype.toDataURL)) {
+    toDataURLOverride.internal = win.HTMLCanvasElement.prototype.toDataURL;
   } else {
-    toDataURLOverride.internal = HTMLCanvasElement.prototype.toDataURL.internal;
+    toDataURLOverride.internal =
+      win.HTMLCanvasElement.prototype.toDataURL.internal;
   }
-  HTMLCanvasElement.prototype.toDataURL = toDataURLOverride;
+  win.HTMLCanvasElement.prototype.toDataURL = toDataURLOverride;
 }
diff --git a/src/window.js b/src/window.js
index 74d8e72..9c79351 100644
--- a/src/window.js
+++ b/src/window.js
@@ -55,7 +55,7 @@ export default (win) => {
   if (!win.ImageBitmap) win.ImageBitmap = ImageBitmap;
   if (!win.createImageBitmap) win.createImageBitmap = createImageBitmap;
 
-  mockPrototype();
+  mockPrototype(win);
 
   return win;
 };
diff --git a/types/index.d.ts b/types/index.d.ts
index e719f28..687ab26 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -1,4 +1,4 @@
-export function setupJestCanvasMock(window?: Window) {}
+export function setupJestCanvasMock(window?: Window): void
 
 export interface CanvasRenderingContext2DEvent {
   /**


Test patch:
diff --git a/__tests__/classes/CanvasGradient.js b/__tests__/classes/CanvasGradient.js
index 79d7676..84a5d25 100644
--- a/__tests__/classes/CanvasGradient.js
+++ b/__tests__/classes/CanvasGradient.js
@@ -24,10 +24,12 @@ describe('CanvasGradient', () => {
 
   [Infinity, NaN, -Infinity].forEach((value) => {
     test('CanvasGradient should throw if offset is ' + value, () => {
-      expect(() => {
+      const fn = () => {
         var grd = ctx.createLinearGradient(1, 2, 3, 4);
         grd.addColorStop(value, 'blue');
-      }).toThrow(DOMException);
+      };
+      expect(fn).toThrow(DOMException);
+      expect(fn).toThrow('is outside the range');
     });
   });
 
diff --git a/__tests__/classes/CanvasRenderingContext2D.addHitRegion.js b/__tests__/classes/CanvasRenderingContext2D.addHitRegion.js
index a95b7e5..cbc6589 100644
--- a/__tests__/classes/CanvasRenderingContext2D.addHitRegion.js
+++ b/__tests__/classes/CanvasRenderingContext2D.addHitRegion.js
@@ -19,13 +19,15 @@ describe('addHitRegion', () => {
   });
 
   it('should throw if called with no parameters', () => {
-    expect(() => ctx.addHitRegion()).toThrow(DOMException);
+    const fn = () => ctx.addHitRegion();
+    expect(fn).toThrow(DOMException);
+    expect(fn).toThrow('Both id and control are null');
   });
 
   it("should throw if fillRule is set and isn't 'evenodd' or 'nonzero'", () => {
-    expect(() =>
-      ctx.addHitRegion({ id: 'test', fillRule: 'wrong!' })
-    ).toThrow();
+    const fn = () => ctx.addHitRegion({ id: 'test', fillRule: 'wrong!' });
+    expect(fn).toThrow(TypeError);
+    expect(fn).toThrow('is not a valid enum value of type CanvasFillRule');
   });
 
   it('should not throw if fillRule is valid', () => {
diff --git a/__tests__/classes/CanvasRenderingContext2D.arc.js b/__tests__/classes/CanvasRenderingContext2D.arc.js
index 548fac1..50a0451 100644
--- a/__tests__/classes/CanvasRenderingContext2D.arc.js
+++ b/__tests__/classes/CanvasRenderingContext2D.arc.js
@@ -18,7 +18,7 @@ describe('arc', () => {
     expect(ctx.arc).toBeCalled();
   });
 
-  it("shouldn't accept parameters less than 7", () => {
+  it("shouldn't accept parameters less than 5", () => {
     expect(() => ctx.arc()).toThrow(TypeError);
     expect(() => ctx.arc(1)).toThrow(TypeError);
     expect(() => ctx.arc(1, 2)).toThrow(TypeError);
@@ -27,7 +27,9 @@ describe('arc', () => {
   });
 
   it('should throw when radius is negative', () => {
-    expect(() => ctx.arc(1, 2, -1, 4, 5)).toThrow(DOMException);
+    const fn = () => ctx.arc(1, 2, -1, 4, 5);
+    expect(fn).toThrow(DOMException);
+    expect(fn).toThrow('The radius provided (-1) is negative.');
   });
 
   it('should not throw if any value is `NaN`', () => {
diff --git a/__tests__/classes/CanvasRenderingContext2D.arcTo.js b/__tests__/classes/CanvasRenderingContext2D.arcTo.js
index 3214414..e68c315 100644
--- a/__tests__/classes/CanvasRenderingContext2D.arcTo.js
+++ b/__tests__/classes/CanvasRenderingContext2D.arcTo.js
@@ -19,11 +19,17 @@ describe('arcTo', () => {
   });
 
   it("shouldn't accept parameters less than 5", () => {
-    expect(() => ctx.arcTo(1, 2, 3)).toThrow(DOMException);
+    expect(() => ctx.arcTo()).toThrow(TypeError);
+    expect(() => ctx.arcTo(1)).toThrow(TypeError);
+    expect(() => ctx.arcTo(1, 2)).toThrow(TypeError);
+    expect(() => ctx.arcTo(1, 2, 3)).toThrow(TypeError);
+    expect(() => ctx.arcTo(1, 2, 3, 4)).toThrow(TypeError);
   });
 
   it('should throw when radius is negative', () => {
-    expect(() => ctx.arcTo(1, 2, -1, 3, -1)).toThrow(TypeError);
+    const fn = () => ctx.arcTo(1, 2, 3, 4, -1);
+    expect(fn).toThrow(DOMException);
+    expect(fn).toThrow('The radius provided (-1) is negative.');
   });
 
   it('should accept 5 parameters regardless of type', () => {
diff --git a/__tests__/classes/CanvasRenderingContext2D.createImagePattern.js b/__tests__/classes/CanvasRenderingContext2D.createImagePattern.js
index ae0a180..1e5daa3 100644
--- a/__tests__/classes/CanvasRenderingContext2D.createImagePattern.js
+++ b/__tests__/classes/CanvasRenderingContext2D.createImagePattern.js
@@ -63,7 +63,9 @@ describe('createImagePattern', () => {
   it('should not create a pattern if the image bitmap is closed', () => {
     const bmp = new ImageBitmap(400, 300);
     bmp.close();
-    expect(() => ctx.createPattern(bmp, 'repeat')).toThrow(DOMException);
+    const fn = () => ctx.createPattern(bmp, 'repeat');
+    expect(fn).toThrow(DOMException);
+    expect(fn).toThrow('The image source is detached.');
   });
 
   it('should create a valid pattern for all repeat types', () => {
diff --git a/__tests__/classes/CanvasRenderingContext2D.createRadialGradient.js b/__tests__/classes/CanvasRenderingContext2D.createRadialGradient.js
index 8410468..46ef160 100644
--- a/__tests__/classes/CanvasRenderingContext2D.createRadialGradient.js
+++ b/__tests__/classes/CanvasRenderingContext2D.createRadialGradient.js
@@ -43,13 +43,16 @@ describe('createRadialGradient', () => {
     );
   });
 
-  it('should not create a radial gradient if any of the radius values are < 0', () => {
-    expect(() => ctx.createRadialGradient(0, 0, -1, 0, 0, 0)).toThrow(
-      DOMException
-    );
-    expect(() => ctx.createRadialGradient(0, 0, 0, 0, 0, -1)).toThrow(
-      DOMException
-    );
+  it('should not create a radial gradient if r0 value is < 0', () => {
+    const fn = () => ctx.createRadialGradient(0, 0, -1, 0, 0, 0);
+    expect(fn).toThrow(DOMException);
+    expect(fn).toThrow('The r0 provided is less than 0.');
+  });
+
+  it('should not create a radial gradient if r1 value is < 0', () => {
+    const fn = () => ctx.createRadialGradient(0, 0, 0, 0, 0, -1);
+    expect(fn).toThrow(DOMException);
+    expect(fn).toThrow('The r1 provided is less than 0.');
   });
 
   it('should create a radial gradient with string values', () => {
diff --git a/__tests__/classes/CanvasRenderingContext2D.drawImage.js b/__tests__/classes/CanvasRenderingContext2D.drawImage.js
index 40daaaf..6a96023 100644
--- a/__tests__/classes/CanvasRenderingContext2D.drawImage.js
+++ b/__tests__/classes/CanvasRenderingContext2D.drawImage.js
@@ -36,7 +36,9 @@ describe('drawImage', () => {
   it('should not draw if the image bitmap is closed', () => {
     const bmp = new ImageBitmap(100, 100);
     bmp.close();
-    expect(() => ctx.drawImage(bmp, 1, 2)).toThrow(DOMException);
+    const fn = () => ctx.drawImage(bmp, 1, 2);
+    expect(fn).toThrow(DOMException);
+    expect(fn).toThrow('The image source is detached.');
   });
 
   it('should accept 3, 5, and 9 parameters', () => {
diff --git a/__tests__/classes/CanvasRenderingContext2D.ellipse.js b/__tests__/classes/CanvasRenderingContext2D.ellipse.js
index 5d5aee0..be2d080 100644
--- a/__tests__/classes/CanvasRenderingContext2D.ellipse.js
+++ b/__tests__/classes/CanvasRenderingContext2D.ellipse.js
@@ -28,9 +28,16 @@ describe('ellipse', () => {
     expect(() => ctx.ellipse(1, 2, 3, 4, 5, 6)).toThrow(TypeError);
   });
 
-  it('should throw when radius is negative', () => {
-    expect(() => ctx.ellipse(1, 2, -1, 4, 5, 6, 7)).toThrow(DOMException);
-    expect(() => ctx.ellipse(1, 2, 3, -1, 5, 6, 7)).toThrow(DOMException);
+  it('should throw when major axis radius is negative', () => {
+    const fn = () => ctx.ellipse(1, 2, -1, 4, 5, 6, 7);
+    expect(fn).toThrow(DOMException);
+    expect(fn).toThrow('The major-axis radius provided (-1) is negative.');
+  });
+
+  it('should throw when minor axis radius is negative', () => {
+    const fn = () => ctx.ellipse(1, 2, 3, -1, 5, 6, 7);
+    expect(fn).toThrow(DOMException);
+    expect(fn).toThrow('The minor-axis radius provided (-1) is negative.');
   });
 
   it('should not throw if any value is `NaN`', () => {
diff --git a/__tests__/classes/CanvasRenderingContext2D.getImageData.js b/__tests__/classes/CanvasRenderingContext2D.getImageData.js
index 39a530b..e58996f 100644
--- a/__tests__/classes/CanvasRenderingContext2D.getImageData.js
+++ b/__tests__/classes/CanvasRenderingContext2D.getImageData.js
@@ -14,18 +14,39 @@ describe('getImageData', () => {
   });
 
   it('should be callable', () => {
-    ctx.getImageData();
+    ctx.getImageData(0, 0, 10, 20);
     expect(ctx.getImageData).toBeCalled();
   });
 
+  it('should throw if less than 4 parameters are given', () => {
+    expect(() => ctx.getImageData()).toThrow(TypeError);
+    expect(() => ctx.getImageData(0)).toThrow(TypeError);
+    expect(() => ctx.getImageData(0, 0)).toThrow(TypeError);
+    expect(() => ctx.getImageData(0, 0, 0)).toThrow(TypeError);
+  });
+
   it('should return a image data from getImageData', () => {
-    expect(ctx.getImageData()).toBeInstanceOf(ImageData);
+    expect(ctx.getImageData(0, 0, 10, 20)).toBeInstanceOf(ImageData);
   });
 
   it('should return a image data from getImageData of proper size', () => {
-    const data = ctx.getImageData();
-    expect(data.width).toBe(400);
-    expect(data.height).toBe(300);
-    expect(data.data.length).toBe(400 * 300 * 4);
+    const data = ctx.getImageData(0, 0, 10, 20);
+    expect(data.width).toBe(10);
+    expect(data.height).toBe(20);
+    expect(data.data.length).toBe(10 * 20 * 4);
+  });
+
+  it('should return image data from getImageData if size is negative', () => {
+    const data = ctx.getImageData(0, 0, -10, -20);
+    expect(data.width).toBe(10);
+    expect(data.height).toBe(20);
+    expect(data.data.length).toBe(10 * 20 * 4);
+  });
+
+  it('should throw if width or height are zero', () => {
+    expect(() => ctx.getImageData(0, 0, 0, 1)).toThrow(DOMException);
+    expect(() => ctx.getImageData(0, 0, 0, 1)).toThrow('source width is 0');
+    expect(() => ctx.getImageData(0, 0, 1, 0)).toThrow('source height is 0');
+    expect(() => ctx.getImageData(0, 0, 0, 0)).toThrow('source width is 0');
   });
 });
diff --git a/__tests__/mock/window.js b/__tests__/mock/window.js
new file mode 100644
index 0000000..b3db593
--- /dev/null
+++ b/__tests__/mock/window.js
@@ -0,0 +1,30 @@
+import { JSDOM } from 'jsdom';
+import mockWindow from '../../src/window';
+
+describe('mockWindow', () => {
+  it('mocks the passed object', () => {
+    const win = new JSDOM().window;
+
+    mockWindow(win);
+
+    expect(win.Path2D).not.toBeNull();
+    expect(win.CanvasGradient).not.toBeNull();
+    expect(win.CanvasPattern).not.toBeNull();
+    expect(win.CanvasRenderingContext2D).not.toBeNull();
+    expect(win.DOMMatrix).not.toBeNull();
+    expect(win.ImageData).not.toBeNull();
+    expect(win.TextMetrics).not.toBeNull();
+    expect(win.ImageBitmap).not.toBeNull();
+    expect(win.createImageBitmap).not.toBeNull();
+
+    expect(
+      jest.isMockFunction(win.HTMLCanvasElement.prototype.getContext)
+    ).toBe(true);
+    expect(jest.isMockFunction(win.HTMLCanvasElement.prototype.toBlob)).toBe(
+      true
+    );
+    expect(jest.isMockFunction(win.HTMLCanvasElement.prototype.toDataURL)).toBe(
+      true
+    );
+  });
+});
diff --git a/__tests__/vis.js b/__tests__/vis.js
index 3dd8925..a3e9949 100644
--- a/__tests__/vis.js
+++ b/__tests__/vis.js
@@ -2,28 +2,23 @@
  * test vis @AntV/G2Plot
  */
 
-import { Line } from '@antv/g2plot';
+// import { Line } from '@antv/g2plot';
 
 describe('vis', () => {
   it('vis can pass', () => {
-    const div = document.createElement('canvas');
-
-    const line = new Line(div, {
-      data: [
-        { x: 'A', y: 10 },
-        { x: 'B', y: 20 },
-        { x: 'C', y: 30 },
-      ],
-      xField: 'x',
-      yField: 'y',
-    });
-
-    line.render();
-
-    expect(line.container.querySelector('canvas')).not.toBe(null);
-
-    line.destroy();
-
-    expect(line.container.querySelector('canvas')).toBe(null);
+    // const div = document.createElement('canvas');
+    // const line = new Line(div, {
+    //   data: [
+    //     { x: 'A', y: 10 },
+    //     { x: 'B', y: 20 },
+    //     { x: 'C', y: 30 },
+    //   ],
+    //   xField: 'x',
+    //   yField: 'y',
+    // });
+    // line.render();
+    // expect(line.container.querySelector('canvas')).not.toBe(null);
+    // line.destroy();
+    // expect(line.container.querySelector('canvas')).toBe(null);
   });
 });