Skip to content

Commit 5cbcac8

Browse files
committed
test(utilities): tests for canTextBeChildOfNode
1 parent 523e292 commit 5cbcac8

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/utilities.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var elementsWithNoTextChildren = new Set([
112112
]);
113113

114114
/**
115-
* Returns True if the the given node can contains text nodes
115+
* Returns True if the the given node can contain text nodes
116116
* @param {DomElement} node
117117
* @returns {boolean}
118118
*/
@@ -125,5 +125,6 @@ module.exports = {
125125
invertObject: invertObject,
126126
isCustomComponent: isCustomComponent,
127127
setStyleProp: setStyleProp,
128-
canTextBeChildOfNode: canTextBeChildOfNode
128+
canTextBeChildOfNode: canTextBeChildOfNode,
129+
elementsWithNoTextChildren: elementsWithNoTextChildren
129130
};

test/utilities.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ const {
33
PRESERVE_CUSTOM_ATTRIBUTES,
44
invertObject,
55
isCustomComponent,
6-
setStyleProp
6+
setStyleProp,
7+
elementsWithNoTextChildren,
8+
canTextBeChildOfNode
79
} = require('../lib/utilities');
810

911
describe('invertObject', () => {
@@ -125,3 +127,22 @@ describe('setStyleProp', () => {
125127
expect(props).toEqual({ style: {} });
126128
});
127129
});
130+
131+
describe('canTextBeChildOfNode', () => {
132+
it.each(Array.from(elementsWithNoTextChildren))(
133+
'returns false since text node can not be child of %s',
134+
nodeName => {
135+
const node = {
136+
name: nodeName
137+
};
138+
expect(canTextBeChildOfNode(node)).toBe(false);
139+
}
140+
);
141+
142+
it('returns true if text can be child of <td/>', () => {
143+
const node = {
144+
name: 'td'
145+
};
146+
expect(canTextBeChildOfNode(node)).toBe(true);
147+
});
148+
});

0 commit comments

Comments
 (0)