Skip to content

Commit 198db6c

Browse files
committed
Add typeOfNode Util.
1 parent 4f03d9e commit 198db6c

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/ReactWrapper.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
mapNativeEventNames,
2222
containsChildrenSubArray,
2323
propsOfNode,
24+
typeOfNode,
2425
} from './Utils';
2526
import {
2627
debugInsts,
@@ -485,10 +486,7 @@ export default class ReactWrapper {
485486
* @returns {String|Function}
486487
*/
487488
type() {
488-
return this.single((n) => {
489-
const node = getNode(n);
490-
return node ? node.type : null;
491-
});
489+
return this.single(n => typeOfNode(getNode(n)));
492490
}
493491

494492
/**

src/ShallowWrapper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
propFromEvent,
88
withSetStateAllowed,
99
propsOfNode,
10+
typeOfNode,
1011
} from './Utils';
1112
import {
1213
debugNodes,
@@ -464,7 +465,7 @@ export default class ShallowWrapper {
464465
* @returns {String|Function}
465466
*/
466467
type() {
467-
return this.single(n => n ? n.type : null);
468+
return this.single(typeOfNode);
468469
}
469470

470471
/**

src/Utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export function propsOfNode(node) {
2020
return (node && node.props) || {};
2121
}
2222

23+
export function typeOfNode(node) {
24+
return node ? node.type : null;
25+
}
26+
2327
export function onPrototype(Component, lifecycle, method) {
2428
const proto = Component.prototype;
2529
Object.getOwnPropertyNames(proto).forEach((name) => {

0 commit comments

Comments
 (0)