jest-canvas-mock 2.3.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## Version 2.5.0
4
+
5
+ - feat: export a function to re-initialize mocks (#98)
6
+ - docs: fix some typos (#104)
7
+ - fix: copy & paste mistake: toBlob -> toDataURL (#101)
8
+ - chore: add Contributors LitoMore (#94)
9
+
10
+ ## Version 2.4.0
11
+
12
+ - fix(window): avoid global.window redefinition (#91)
13
+ - feat: add translate, translateSelf, scale and scaleSelf to DOMMatrix (#83)
14
+ - optimize(Path2D): replace reassign-concat with for-push (#76)
15
+ - test: add test for vis @antv/g2plot (#79)
16
+ - fix(setLineDash): rename parameter value to segments (#74)
17
+ - fix(clip): delete clipping region with restore (#73)
18
+
3
19
  ## Version 2.3.0
4
20
 
5
21
  - Added Prettier code style
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > Mock `canvas` when run unit test cases with jest. For more browser environment, you can use [jest-electron](https://github.com/hustcc/jest-electron) for real browser runtime.
4
4
 
5
- [![Build Status](https://travis-ci.org/hustcc/jest-canvas-mock.svg?branch=master)](https://travis-ci.org/hustcc/jest-canvas-mock)
5
+ [![Build Status](https://github.com/hustcc/jest-canvas-mock/workflows/build/badge.svg)](https://github.com/hustcc/jest-canvas-mock/actions/workflows/build.yml)
6
6
  [![Coverage Status](https://coveralls.io/repos/github/hustcc/jest-canvas-mock/badge.svg?branch=master)](https://coveralls.io/github/hustcc/jest-canvas-mock)
7
7
  [![npm](https://img.shields.io/npm/v/jest-canvas-mock.svg)](https://www.npmjs.com/package/jest-canvas-mock)
8
8
  [![npm](https://img.shields.io/npm/dm/jest-canvas-mock.svg)](https://www.npmjs.com/package/jest-canvas-mock)
@@ -63,6 +63,20 @@ Add that file to your `setupFiles` array:
63
63
  }
64
64
  ```
65
65
 
66
+ ## Reset
67
+
68
+ If you reset the jest mocks (for example, with `jest.resetAllMocks()`), you can
69
+ call `setupJestCanvasMock()` to re-create it.
70
+
71
+ ```
72
+ import { setupJestCanvasMock } from 'jest-canvas-mock';
73
+
74
+ beforeEach(() => {
75
+ jest.resetAllMocks();
76
+ setupJestCanvasMock();
77
+ });
78
+ ```
79
+
66
80
  ## Mock Strategy
67
81
 
68
82
  This mock strategy implements all the canvas functions and actually verifies the parameters. If a
@@ -179,6 +193,8 @@ canvas.toDataURL.mockReturnValueOnce(
179
193
  - [@jtenner](https://github.com/jtenner)
180
194
  - [@evanoc0](https://github.com/evanoc0)
181
195
  - [@lekha](https://github.com/lekha)
196
+ - [@yonatankra](https://github.com/yonatankra)
197
+ - [@LitoMore](https://github.com/LitoMore)
182
198
 
183
199
  ## License
184
200
 
@@ -4,28 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _mooColor = require("moo-color");
9
-
10
8
  class CanvasGradient {
11
9
  constructor() {
12
10
  this.addColorStop = jest.fn(this.addColorStop.bind(this));
13
11
  }
14
-
15
12
  addColorStop(offset, color) {
16
13
  const numoffset = Number(offset);
17
-
18
14
  if (!Number.isFinite(numoffset) || numoffset < 0 || numoffset > 1) {
19
15
  throw new DOMException('IndexSizeError', "Failed to execute 'addColorStop' on 'CanvasGradient': The provided value ('" + numoffset + "') is outside the range (0.0, 1.0)");
20
16
  }
21
-
22
17
  try {
23
18
  new _mooColor.MooColor(color);
24
19
  } catch (e) {
25
20
  throw new SyntaxError("Failed to execute 'addColorStop' on 'CanvasGradient': The value provided ('" + color + "') could not be parsed as a color.");
26
21
  }
27
22
  }
28
-
29
23
  }
30
-
31
24
  exports.default = CanvasGradient;
@@ -4,16 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  class CanvasPattern {
9
8
  constructor() {
10
9
  this.setTransform = jest.fn(this.setTransform.bind(this));
11
10
  }
12
-
13
11
  setTransform(value) {
14
12
  if (arguments.length > 0 && !(value instanceof Object)) throw new TypeError("Failed to execute 'setTransform' on 'CanvasPattern': parameter 1 ('transform') is not an object.");
15
13
  }
16
-
17
14
  }
18
-
19
15
  exports.default = CanvasPattern;