@pie-lib/test-utils 0.2.33 → 0.3.0-beta.2
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 +19 -15
- package/NEXT.CHANGELOG.json +1 -0
- package/package.json +2 -2
- package/src/__tests__/index.test.js +45 -0
- package/.travis.yml +0 -7
- package/README.md +0 -23
- package/lib/index.js +0 -40
- package/lib/index.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
# [0.3.0-beta.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.33...@pie-lib/test-utils@0.3.0-beta.2) (2025-07-20)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @pie-lib/test-utils
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
# [0.3.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.33...@pie-lib/test-utils@0.3.0-beta.1) (2025-07-20)
|
|
15
15
|
|
|
16
16
|
**Note:** Version bump only for package @pie-lib/test-utils
|
|
17
17
|
|
|
@@ -19,7 +19,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
# [0.3.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.33...@pie-lib/test-utils@0.3.0-beta.1) (2025-07-20)
|
|
23
23
|
|
|
24
24
|
**Note:** Version bump only for package @pie-lib/test-utils
|
|
25
25
|
|
|
@@ -27,7 +27,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
# [0.3.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.33...@pie-lib/test-utils@0.3.0-beta.0) (2025-07-20)
|
|
31
31
|
|
|
32
32
|
**Note:** Version bump only for package @pie-lib/test-utils
|
|
33
33
|
|
|
@@ -35,46 +35,50 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
# [0.4.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.33...@pie-lib/test-utils@0.4.0-beta.0) (2025-07-15)
|
|
39
39
|
|
|
40
40
|
**Note:** Version bump only for package @pie-lib/test-utils
|
|
41
41
|
|
|
42
|
+
# [0.3.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.33...@pie-lib/test-utils@0.3.0-beta.0) (2025-07-15)
|
|
42
43
|
|
|
44
|
+
**Note:** Version bump only for package @pie-lib/test-utils
|
|
43
45
|
|
|
46
|
+
## [0.2.33](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.32...@pie-lib/test-utils@0.2.33) (2023-06-24)
|
|
44
47
|
|
|
48
|
+
**Note:** Version bump only for package @pie-lib/test-utils
|
|
45
49
|
|
|
46
|
-
## [0.2.
|
|
50
|
+
## [0.2.32](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.30...@pie-lib/test-utils@0.2.32) (2023-01-31)
|
|
47
51
|
|
|
48
52
|
**Note:** Version bump only for package @pie-lib/test-utils
|
|
49
53
|
|
|
54
|
+
## [0.2.30](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.29...@pie-lib/test-utils@0.2.30) (2023-01-31)
|
|
50
55
|
|
|
56
|
+
**Note:** Version bump only for package @pie-lib/test-utils
|
|
51
57
|
|
|
58
|
+
## [0.2.29](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.28...@pie-lib/test-utils@0.2.29) (2023-01-31)
|
|
52
59
|
|
|
60
|
+
**Note:** Version bump only for package @pie-lib/test-utils
|
|
53
61
|
|
|
54
|
-
## [0.2.
|
|
62
|
+
## [0.2.28](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.27...@pie-lib/test-utils@0.2.28) (2023-01-31)
|
|
55
63
|
|
|
56
64
|
**Note:** Version bump only for package @pie-lib/test-utils
|
|
57
65
|
|
|
66
|
+
## [0.2.27](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.24...@pie-lib/test-utils@0.2.27) (2023-01-31)
|
|
58
67
|
|
|
68
|
+
**Note:** Version bump only for package @pie-lib/test-utils
|
|
59
69
|
|
|
70
|
+
## [0.2.24](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.22...@pie-lib/test-utils@0.2.24) (2023-01-31)
|
|
60
71
|
|
|
72
|
+
**Note:** Version bump only for package @pie-lib/test-utils
|
|
61
73
|
|
|
62
74
|
## [0.2.22](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.20...@pie-lib/test-utils@0.2.22) (2023-01-31)
|
|
63
75
|
|
|
64
76
|
**Note:** Version bump only for package @pie-lib/test-utils
|
|
65
77
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
78
|
## [0.2.20](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.19...@pie-lib/test-utils@0.2.20) (2022-11-23)
|
|
71
79
|
|
|
72
80
|
**Note:** Version bump only for package @pie-lib/test-utils
|
|
73
81
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
82
|
## [0.2.19](https://github.com/pie-framework/pie-lib/compare/@pie-lib/test-utils@0.2.17...@pie-lib/test-utils@0.2.19) (2021-06-25)
|
|
79
83
|
|
|
80
84
|
**Note:** Version bump only for package @pie-lib/test-utils
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/test-utils",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "0.3.0-beta.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
"enzyme": "^3.8.0",
|
|
14
14
|
"react": "^16.8.1"
|
|
15
15
|
},
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "e2aa3ddac60f49bcb8c2562370f496323642f453",
|
|
17
17
|
"scripts": {}
|
|
18
18
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { shallowChild } from '../index';
|
|
3
|
+
import Enzyme from 'enzyme';
|
|
4
|
+
import Adapter from 'enzyme-adapter-react-16';
|
|
5
|
+
|
|
6
|
+
Enzyme.configure({ adapter: new Adapter() });
|
|
7
|
+
|
|
8
|
+
describe('test-utils', () => {
|
|
9
|
+
describe('shallowChild', () => {
|
|
10
|
+
function simpleHoC(WrappedComponent) {
|
|
11
|
+
return class extends React.Component {
|
|
12
|
+
render() {
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
<WrappedComponent oneMoreProp="hello" {...this.props} />
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class SimpleComponent extends React.Component {
|
|
23
|
+
render() {
|
|
24
|
+
return <span>My simple component will get wrapped</span>;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
it('moves past HoC and returns shallow rendered component using enzyme', () => {
|
|
29
|
+
const wrapper = shallowChild(simpleHoC(SimpleComponent), null, 1);
|
|
30
|
+
const shallowComponent = wrapper();
|
|
31
|
+
|
|
32
|
+
expect(shallowComponent.find(SimpleComponent).length).toEqual(1);
|
|
33
|
+
expect(shallowComponent.props().children.props.oneMoreProp).toEqual('hello');
|
|
34
|
+
expect(shallowComponent.html().includes('span')).toEqual(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('overwrites specific props when passed into the closure', () => {
|
|
38
|
+
const wrapper = shallowChild(simpleHoC(SimpleComponent), null, 1);
|
|
39
|
+
const shallowComponent = wrapper({ oneMoreProp: 'helloToo' });
|
|
40
|
+
|
|
41
|
+
expect(shallowComponent.find(SimpleComponent).length).toEqual(1);
|
|
42
|
+
expect(shallowComponent.props().children.props.oneMoreProp).toEqual('helloToo');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
package/.travis.yml
DELETED
package/README.md
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# test-utils
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
`test-utils` is a small collection of tools and helper functions that facilitate testing for components of the PIE framework.
|
|
5
|
-
|
|
6
|
-
## Usage
|
|
7
|
-
|
|
8
|
-
### Install
|
|
9
|
-
|
|
10
|
-
npm install --save @pie-lib/test-utils
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
### Import
|
|
14
|
-
|
|
15
|
-
import { shallowChild } from '@pie-lib/test-utils';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
### Use it for testing HoC wrapped components
|
|
19
|
-
|
|
20
|
-
const wrapper = shallowChild(ComponentX, defaultProps, 1); // 1 being nest level, for instance Material-UI styles wrapper HoC
|
|
21
|
-
const componentWithSpecificProps = wrapper(specificProps);
|
|
22
|
-
|
|
23
|
-
expect(componentWithSpecificProps.find('div').length).toEqual(1);
|
package/lib/index.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
exports.shallowChild = shallowChild;
|
|
11
|
-
|
|
12
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
-
|
|
14
|
-
var React = _interopRequireWildcard(require("react"));
|
|
15
|
-
|
|
16
|
-
var _enzyme = require("enzyme");
|
|
17
|
-
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
|
-
function shallowChild(Component) {
|
|
23
|
-
var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
24
|
-
var nestLevel = arguments.length > 2 ? arguments[2] : undefined;
|
|
25
|
-
return function innerRender() {
|
|
26
|
-
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
27
|
-
var rendered = (0, _enzyme.shallow)( /*#__PURE__*/React.createElement(Component, (0, _extends2["default"])({}, defaultProps, props)));
|
|
28
|
-
|
|
29
|
-
if (nestLevel) {
|
|
30
|
-
var repeat = nestLevel;
|
|
31
|
-
|
|
32
|
-
while (repeat--) {
|
|
33
|
-
rendered = rendered.first().shallow();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return rendered;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":["shallowChild","Component","defaultProps","nestLevel","innerRender","props","rendered","repeat","first","shallow"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;;;;;AAEO,SAASA,YAAT,CAAsBC,SAAtB,EAA+D;AAAA,MAA9BC,YAA8B,uEAAf,EAAe;AAAA,MAAXC,SAAW;AACpE,SAAO,SAASC,WAAT,GAAiC;AAAA,QAAZC,KAAY,uEAAJ,EAAI;AACtC,QAAIC,QAAQ,GAAG,mCAAQ,oBAAC,SAAD,gCAAeJ,YAAf,EAAiCG,KAAjC,EAAR,CAAf;;AAEA,QAAIF,SAAJ,EAAe;AACb,UAAII,MAAM,GAAGJ,SAAb;;AAEA,aAAOI,MAAM,EAAb,EAAiB;AACfD,QAAAA,QAAQ,GAAGA,QAAQ,CAACE,KAAT,GAAiBC,OAAjB,EAAX;AACD;AACF;;AAED,WAAOH,QAAP;AACD,GAZD;AAaD","sourcesContent":["import * as React from 'react';\nimport { shallow } from 'enzyme';\n\nexport function shallowChild(Component, defaultProps = {}, nestLevel) {\n return function innerRender(props = {}) {\n let rendered = shallow(<Component {...defaultProps} {...props} />);\n\n if (nestLevel) {\n let repeat = nestLevel;\n\n while (repeat--) {\n rendered = rendered.first().shallow();\n }\n }\n\n return rendered;\n };\n}\n"],"file":"index.js"}
|