@rokkit/helpers 1.0.0-next.151 → 1.0.0-next.153

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/helpers",
3
- "version": "1.0.0-next.151",
3
+ "version": "1.0.0-next.153",
4
4
  "description": "Custom matchers for vitest, mocks and simulators for testing.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -7,6 +7,11 @@ if (!global.Element.prototype.getAnimations) {
7
7
 
8
8
  // Use getter/setter so Svelte's `animation.onfinish = callback` assignment
9
9
  // immediately queues the callback, simulating instant animation completion.
10
+ const animationEffect = {
11
+ getTiming: vi.fn(),
12
+ getComputedTiming: vi.fn()
13
+ }
14
+
10
15
  function createAnimationMock() {
11
16
  let _onfinish = null
12
17
  let _oncancel = null
@@ -18,10 +23,7 @@ function createAnimationMock() {
18
23
  reverse: vi.fn(),
19
24
  persist: vi.fn(),
20
25
  get onfinish() { return _onfinish },
21
- set onfinish(cb) {
22
- _onfinish = cb
23
- if (cb) queueMicrotask(() => cb())
24
- },
26
+ set onfinish(cb) { _onfinish = cb; if (cb) queueMicrotask(() => cb()) },
25
27
  get oncancel() { return _oncancel },
26
28
  set oncancel(cb) { _oncancel = cb },
27
29
  currentTime: 0,
@@ -29,10 +31,7 @@ function createAnimationMock() {
29
31
  playbackRate: 1,
30
32
  playState: 'finished',
31
33
  finished: Promise.resolve(),
32
- effect: {
33
- getTiming: vi.fn(),
34
- getComputedTiming: vi.fn()
35
- }
34
+ effect: animationEffect
36
35
  }
37
36
  }
38
37
 
@@ -72,6 +72,11 @@ export const matchMediaMock = vi.fn().mockImplementation((query) => {
72
72
  removeListener: vi
73
73
  .fn()
74
74
  .mockImplementation((listener) => listeners.splice(listeners.indexOf(listener), 1)),
75
+ addEventListener: vi.fn().mockImplementation((_type, listener) => listeners.push(listener)),
76
+ removeEventListener: vi
77
+ .fn()
78
+ .mockImplementation((_type, listener) => listeners.splice(listeners.indexOf(listener), 1)),
79
+ dispatchEvent: vi.fn(),
75
80
  handler
76
81
  }
77
82
  watchMediaQueries.push(queryObject)