jest-canvas-mock 2.4.0 → 2.5.1

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,12 @@
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
+
3
10
  ## Version 2.4.0
4
11
 
5
12
  - fix(window): avoid global.window redefinition (#91)
package/README.md CHANGED
@@ -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
@@ -181,6 +195,8 @@ canvas.toDataURL.mockReturnValueOnce(
181
195
  - [@lekha](https://github.com/lekha)
182
196
  - [@yonatankra](https://github.com/yonatankra)
183
197
  - [@LitoMore](https://github.com/LitoMore)
198
+ - [@hrd543](https://github.com/hrd543)
199
+ - [@danielrentz](https://github.com/danielrentz)
184
200
 
185
201
  ## License
186
202
 
@@ -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
- throw new DOMException('IndexSizeError', "Failed to execute 'addColorStop' on 'CanvasGradient': The provided value ('" + numoffset + "') is outside the range (0.0, 1.0)");
15
+ throw new DOMException("Failed to execute 'addColorStop' on 'CanvasGradient': The provided value ('" + numoffset + "') is outside the range (0.0, 1.0)", 'IndexSizeError');
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;