@pingux/astro 2.33.0-alpha.5 → 2.33.0-alpha.6
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/lib/cjs/hooks/usePropWarning/index.d.ts +1 -0
- package/lib/cjs/hooks/usePropWarning/usePropWarning.d.ts +13 -0
- package/lib/cjs/hooks/usePropWarning/usePropWarning.js +0 -8
- package/lib/cjs/hooks/usePropWarning/usePropWarning.test.d.ts +1 -0
- package/lib/cjs/hooks/usePropWarning/usePropWarning.test.js +13 -9
- package/lib/hooks/usePropWarning/usePropWarning.js +0 -8
- package/lib/hooks/usePropWarning/usePropWarning.test.js +13 -9
- package/package.json +1 -1
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './usePropWarning';
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
interface UsePropWarning {
|
3
|
+
/**
|
4
|
+
* Provides a development-only console warning for props that we don't want consumers to use
|
5
|
+
* @param {Object} props - The whole props object
|
6
|
+
* @param {String} propToWarn - Specify prop to warn not to use
|
7
|
+
* @param {String} propToUse - Specify prop that should be used instead
|
8
|
+
* @param {Boolean} [allowDuplicates] - If allow duplicate warning messages
|
9
|
+
*/
|
10
|
+
(props: React.ComponentProps<React.ComponentType>, propToWarn: string, propToUse: string, allowDuplicates?: boolean): void;
|
11
|
+
}
|
12
|
+
declare const usePropWarning: UsePropWarning;
|
13
|
+
export default usePropWarning;
|
@@ -10,14 +10,6 @@ var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable
|
|
10
10
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
11
11
|
var _react = require("react");
|
12
12
|
var alreadyShown = new _set["default"]();
|
13
|
-
|
14
|
-
/**
|
15
|
-
* Provides a development-only console warning for props that we don't want consumers to use
|
16
|
-
* @param {Object} props - The whole props object
|
17
|
-
* @param {String} propToWarn - Specify prop to warn not to use
|
18
|
-
* @param {String} propToUse - Specify prop that should be used instead
|
19
|
-
* @param {Boolean} [allowDuplicates] - If allow duplicate warning messages
|
20
|
-
*/
|
21
13
|
var usePropWarning = function usePropWarning(props, propToWarn, propToUse, allowDuplicates) {
|
22
14
|
(0, _react.useEffect)(function () {
|
23
15
|
if (!allowDuplicates && alreadyShown.has(propToWarn)) {
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -7,7 +7,7 @@ describe('usePropWarning', function () {
|
|
7
7
|
beforeEach(function () {
|
8
8
|
process.env.NODE_ENV = 'development';
|
9
9
|
global.console.warn = function () {
|
10
|
-
return jest.
|
10
|
+
return jest.fn();
|
11
11
|
}; // eslint-disable-line no-console
|
12
12
|
});
|
13
13
|
|
@@ -16,8 +16,9 @@ describe('usePropWarning', function () {
|
|
16
16
|
jest.clearAllMocks();
|
17
17
|
});
|
18
18
|
test('default', function () {
|
19
|
-
var props = {
|
20
|
-
|
19
|
+
var props = {
|
20
|
+
disabled: true
|
21
|
+
};
|
21
22
|
var spy = jest.spyOn(console, 'warn');
|
22
23
|
expect(spy).not.toHaveBeenCalled();
|
23
24
|
(0, _reactHooks.renderHook)(function () {
|
@@ -26,8 +27,9 @@ describe('usePropWarning', function () {
|
|
26
27
|
expect(spy).toHaveBeenCalledTimes(1);
|
27
28
|
});
|
28
29
|
test('does not warn if prop does not exist', function () {
|
29
|
-
var props = {
|
30
|
-
|
30
|
+
var props = {
|
31
|
+
isDisabled: true
|
32
|
+
};
|
31
33
|
var spy = jest.spyOn(console, 'warn');
|
32
34
|
expect(spy).not.toHaveBeenCalled();
|
33
35
|
(0, _reactHooks.renderHook)(function () {
|
@@ -36,8 +38,9 @@ describe('usePropWarning', function () {
|
|
36
38
|
expect(spy).not.toHaveBeenCalled();
|
37
39
|
});
|
38
40
|
test('showns duplicated messages if explicitly allowed', function () {
|
39
|
-
var props = {
|
40
|
-
|
41
|
+
var props = {
|
42
|
+
disabled: true
|
43
|
+
};
|
41
44
|
var spy = jest.spyOn(console, 'warn');
|
42
45
|
(0, _reactHooks.renderHook)(function () {
|
43
46
|
return (0, _usePropWarning["default"])(props, 'disabled', 'isDisabled', true);
|
@@ -49,8 +52,9 @@ describe('usePropWarning', function () {
|
|
49
52
|
});
|
50
53
|
test('does not warn if it is in production environment', function () {
|
51
54
|
process.env.NODE_ENV = 'production';
|
52
|
-
var props = {
|
53
|
-
|
55
|
+
var props = {
|
56
|
+
disabled: true
|
57
|
+
};
|
54
58
|
var spy = jest.spyOn(console, 'warn');
|
55
59
|
expect(spy).not.toHaveBeenCalled();
|
56
60
|
(0, _reactHooks.renderHook)(function () {
|
@@ -2,14 +2,6 @@ import _Set from "@babel/runtime-corejs3/core-js-stable/set";
|
|
2
2
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
3
3
|
import { useEffect } from 'react';
|
4
4
|
var alreadyShown = new _Set();
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Provides a development-only console warning for props that we don't want consumers to use
|
8
|
-
* @param {Object} props - The whole props object
|
9
|
-
* @param {String} propToWarn - Specify prop to warn not to use
|
10
|
-
* @param {String} propToUse - Specify prop that should be used instead
|
11
|
-
* @param {Boolean} [allowDuplicates] - If allow duplicate warning messages
|
12
|
-
*/
|
13
5
|
var usePropWarning = function usePropWarning(props, propToWarn, propToUse, allowDuplicates) {
|
14
6
|
useEffect(function () {
|
15
7
|
if (!allowDuplicates && alreadyShown.has(propToWarn)) {
|
@@ -4,7 +4,7 @@ describe('usePropWarning', function () {
|
|
4
4
|
beforeEach(function () {
|
5
5
|
process.env.NODE_ENV = 'development';
|
6
6
|
global.console.warn = function () {
|
7
|
-
return jest.
|
7
|
+
return jest.fn();
|
8
8
|
}; // eslint-disable-line no-console
|
9
9
|
});
|
10
10
|
|
@@ -13,8 +13,9 @@ describe('usePropWarning', function () {
|
|
13
13
|
jest.clearAllMocks();
|
14
14
|
});
|
15
15
|
test('default', function () {
|
16
|
-
var props = {
|
17
|
-
|
16
|
+
var props = {
|
17
|
+
disabled: true
|
18
|
+
};
|
18
19
|
var spy = jest.spyOn(console, 'warn');
|
19
20
|
expect(spy).not.toHaveBeenCalled();
|
20
21
|
renderHook(function () {
|
@@ -23,8 +24,9 @@ describe('usePropWarning', function () {
|
|
23
24
|
expect(spy).toHaveBeenCalledTimes(1);
|
24
25
|
});
|
25
26
|
test('does not warn if prop does not exist', function () {
|
26
|
-
var props = {
|
27
|
-
|
27
|
+
var props = {
|
28
|
+
isDisabled: true
|
29
|
+
};
|
28
30
|
var spy = jest.spyOn(console, 'warn');
|
29
31
|
expect(spy).not.toHaveBeenCalled();
|
30
32
|
renderHook(function () {
|
@@ -33,8 +35,9 @@ describe('usePropWarning', function () {
|
|
33
35
|
expect(spy).not.toHaveBeenCalled();
|
34
36
|
});
|
35
37
|
test('showns duplicated messages if explicitly allowed', function () {
|
36
|
-
var props = {
|
37
|
-
|
38
|
+
var props = {
|
39
|
+
disabled: true
|
40
|
+
};
|
38
41
|
var spy = jest.spyOn(console, 'warn');
|
39
42
|
renderHook(function () {
|
40
43
|
return usePropWarning(props, 'disabled', 'isDisabled', true);
|
@@ -46,8 +49,9 @@ describe('usePropWarning', function () {
|
|
46
49
|
});
|
47
50
|
test('does not warn if it is in production environment', function () {
|
48
51
|
process.env.NODE_ENV = 'production';
|
49
|
-
var props = {
|
50
|
-
|
52
|
+
var props = {
|
53
|
+
disabled: true
|
54
|
+
};
|
51
55
|
var spy = jest.spyOn(console, 'warn');
|
52
56
|
expect(spy).not.toHaveBeenCalled();
|
53
57
|
renderHook(function () {
|