piral-hooks-utils 1.3.3-beta.6187 → 1.3.3-beta.6201

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": "piral-hooks-utils",
3
- "version": "1.3.3-beta.6187",
3
+ "version": "1.3.3-beta.6201",
4
4
  "description": "Hooks and HOC for pilets and Piral instances.",
5
5
  "keywords": [
6
6
  "piral",
@@ -57,5 +57,5 @@
57
57
  "typedoc": "typedoc --json ../../../docs/types/piral-hooks-utils.json src --exclude \"src/**/*.test.*\"",
58
58
  "test": "echo \"Error: run tests from root\" && exit 1"
59
59
  },
60
- "gitHead": "3da0780821a0aeef693b36d08dcf45eeb462d599"
60
+ "gitHead": "6e9f4e6f83514b5c38960ce015e073efc668f3d6"
61
61
  }
@@ -1,11 +1,15 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
1
4
  import * as React from 'react';
5
+ import { describe, it, expect, vitest } from 'vitest';
2
6
  import { useLockBodyScroll } from './lockBodyScroll';
3
7
 
4
- jest.mock('react');
8
+ vitest.mock('react');
5
9
 
6
10
  describe('LockBodyScroll Hook Module', () => {
7
11
  it('sets the body overflow to hidden on being initiated', () => {
8
- const usedEffect = jest.fn();
12
+ const usedEffect = vitest.fn();
9
13
  (React as any).useLayoutEffect = usedEffect;
10
14
  useLockBodyScroll();
11
15
  expect(usedEffect).toHaveBeenCalled();
@@ -14,7 +18,7 @@ describe('LockBodyScroll Hook Module', () => {
14
18
  });
15
19
 
16
20
  it('sets the body overflow to visible on cleanup', () => {
17
- const usedEffect = jest.fn();
21
+ const usedEffect = vitest.fn();
18
22
  (React as any).useLayoutEffect = usedEffect;
19
23
  useLockBodyScroll();
20
24
  const cleanup = usedEffect.mock.calls[0][0]();
@@ -1,17 +1,21 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
1
4
  import * as React from 'react';
5
+ import { describe, it, expect, vitest } from 'vitest';
2
6
  import { useOnClickOutside } from './onClickOutside';
3
7
 
4
- jest.mock('react');
8
+ vitest.mock('react');
5
9
 
6
10
  describe('OnClickOutside Module', () => {
7
11
  it('is properly hooked on when initiating the effect', () => {
8
- const usedEffect = jest.fn();
12
+ const usedEffect = vitest.fn();
9
13
  const originalAdd = document.addEventListener;
10
14
  const originalRemove = document.addEventListener;
11
- document.addEventListener = jest.fn();
12
- document.removeEventListener = jest.fn();
15
+ document.addEventListener = vitest.fn();
16
+ document.removeEventListener = vitest.fn();
13
17
  (React as any).useEffect = usedEffect;
14
- useOnClickOutside({ current: {} as any }, jest.fn());
18
+ useOnClickOutside({ current: {} as any }, vitest.fn());
15
19
  expect(usedEffect).toHaveBeenCalled();
16
20
  const cleanup = usedEffect.mock.calls[0][0]();
17
21
  cleanup();
@@ -21,13 +25,13 @@ describe('OnClickOutside Module', () => {
21
25
  });
22
26
 
23
27
  it('is properly cleaned up when leaving the effect', () => {
24
- const usedEffect = jest.fn();
28
+ const usedEffect = vitest.fn();
25
29
  const originalAdd = document.addEventListener;
26
30
  const originalRemove = document.addEventListener;
27
- document.addEventListener = jest.fn();
28
- document.removeEventListener = jest.fn();
31
+ document.addEventListener = vitest.fn();
32
+ document.removeEventListener = vitest.fn();
29
33
  (React as any).useEffect = usedEffect;
30
- useOnClickOutside({ current: {} as any }, jest.fn());
34
+ useOnClickOutside({ current: {} as any }, vitest.fn());
31
35
  expect(usedEffect).toHaveBeenCalled();
32
36
  const cleanup = usedEffect.mock.calls[0][0]();
33
37
  cleanup();
@@ -37,8 +41,8 @@ describe('OnClickOutside Module', () => {
37
41
  });
38
42
 
39
43
  it('not calling the handler on mousedown if no ref is available', () => {
40
- const usedEffect = jest.fn();
41
- const handler = jest.fn();
44
+ const usedEffect = vitest.fn();
45
+ const handler = vitest.fn();
42
46
  (React as any).useEffect = usedEffect;
43
47
  useOnClickOutside({ current: undefined }, handler);
44
48
  const cleanup = usedEffect.mock.calls[0][0]();
@@ -49,8 +53,8 @@ describe('OnClickOutside Module', () => {
49
53
  });
50
54
 
51
55
  it('not calling the handler on mousedown if ref is available, but contains the node', () => {
52
- const usedEffect = jest.fn();
53
- const handler = jest.fn();
56
+ const usedEffect = vitest.fn();
57
+ const handler = vitest.fn();
54
58
  (React as any).useEffect = usedEffect;
55
59
  useOnClickOutside(
56
60
  {
@@ -70,8 +74,8 @@ describe('OnClickOutside Module', () => {
70
74
  });
71
75
 
72
76
  it('called the handler on mousedown if ref is available and does not contain node', () => {
73
- const usedEffect = jest.fn();
74
- const handler = jest.fn();
77
+ const usedEffect = vitest.fn();
78
+ const handler = vitest.fn();
75
79
  (React as any).useEffect = usedEffect;
76
80
  useOnClickOutside(
77
81
  {
@@ -91,8 +95,8 @@ describe('OnClickOutside Module', () => {
91
95
  });
92
96
 
93
97
  it('called the handler on touchstart if ref is available and does not contain node', () => {
94
- const usedEffect = jest.fn();
95
- const handler = jest.fn();
98
+ const usedEffect = vitest.fn();
99
+ const handler = vitest.fn();
96
100
  (React as any).useEffect = usedEffect;
97
101
  useOnClickOutside(
98
102
  {
@@ -1,9 +1,13 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
1
4
  import * as React from 'react';
5
+ import { describe, it, expect, vitest } from 'vitest';
2
6
  import { useOnScreenVisible } from './onScreenVisible';
3
7
 
4
- jest.mock('react');
8
+ vitest.mock('react');
5
9
 
6
- (React as any).useState = (result) => [result, jest.fn()];
10
+ (React as any).useState = (result) => [result, vitest.fn()];
7
11
 
8
12
  function mockIntersectionObserver() {
9
13
  const instances = [];
@@ -12,9 +16,9 @@ function mockIntersectionObserver() {
12
16
  instances.push(this);
13
17
  this.init(cb, margin);
14
18
  }
15
- init = jest.fn();
16
- observe = jest.fn();
17
- unobserve = jest.fn();
19
+ init = vitest.fn();
20
+ observe = vitest.fn();
21
+ unobserve = vitest.fn();
18
22
  };
19
23
  return instances;
20
24
  }
@@ -26,7 +30,7 @@ describe('OnScreenVisible Module', () => {
26
30
  });
27
31
 
28
32
  it('creates one intersection observer with effect', () => {
29
- const usedEffect = jest.fn();
33
+ const usedEffect = vitest.fn();
30
34
  (React as any).useEffect = usedEffect;
31
35
  const instances = mockIntersectionObserver();
32
36
  useOnScreenVisible({ current: undefined });
@@ -36,7 +40,7 @@ describe('OnScreenVisible Module', () => {
36
40
  });
37
41
 
38
42
  it('does not observe if no ref given', () => {
39
- const usedEffect = jest.fn();
43
+ const usedEffect = vitest.fn();
40
44
  (React as any).useEffect = usedEffect;
41
45
  const instances = mockIntersectionObserver();
42
46
  useOnScreenVisible({ current: undefined });
@@ -46,7 +50,7 @@ describe('OnScreenVisible Module', () => {
46
50
  });
47
51
 
48
52
  it('does observe if valid ref given', () => {
49
- const usedEffect = jest.fn();
53
+ const usedEffect = vitest.fn();
50
54
  (React as any).useEffect = usedEffect;
51
55
  const instances = mockIntersectionObserver();
52
56
  useOnScreenVisible({ current: {} as any });
@@ -56,7 +60,7 @@ describe('OnScreenVisible Module', () => {
56
60
  });
57
61
 
58
62
  it('calls setIntersecting if something changes', () => {
59
- const usedEffect = jest.fn();
63
+ const usedEffect = vitest.fn();
60
64
  (React as any).useEffect = usedEffect;
61
65
  const instances = mockIntersectionObserver();
62
66
  useOnScreenVisible({ current: {} as any });