Skip to content

Commit 91729ec

Browse files
committed
Add tests for void elements
1 parent d03f1a5 commit 91729ec

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

test/integration/integration.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,8 @@ describe('Integration tests: ', () => {
7373
test('<body>test</body>', '<div>test</div>');
7474
});
7575

76+
it('should not allow nesting of void elements', () => {
77+
test('<img><p>test</p></img>', '<img/><p>test</p>');
78+
});
79+
7680
});

test/unit/elementTypes/TagElementType.spec.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
const GeneratePropsFromAttributes = jasmine.createSpy('GeneratePropsFromAttributes').and.callFake(attrs => attrs);
22
const ProcessNodes = jasmine.createSpy('ProcessNodes').and.returnValue('children');
3+
const isVoidElement = jasmine.createSpy('isVoidElement').and.returnValue(false);
34

45
const TagElementType = require('inject!elementTypes/TagElementType')({
56
'../utils/GeneratePropsFromAttributes': GeneratePropsFromAttributes,
6-
'../utils/ProcessNodes': ProcessNodes
7+
'../utils/ProcessNodes': ProcessNodes,
8+
'../utils/isVoidElement': isVoidElement
79
}).default;
810

911
describe('Testing `elementTypes/TagElementType', () => {
1012

1113
beforeEach(() => {
1214
GeneratePropsFromAttributes.calls.reset();
1315
ProcessNodes.calls.reset();
16+
isVoidElement.calls.reset();
1417
});
1518

1619
it('should return a React element corresponding to the node name', () => {
@@ -33,4 +36,21 @@ describe('Testing `elementTypes/TagElementType', () => {
3336

3437
});
3538

39+
it('should not pass though children for void elements', () => {
40+
41+
const voidNode = {
42+
name: 'void',
43+
attribs: {
44+
id: 'test'
45+
},
46+
children: 'child'
47+
};
48+
isVoidElement.and.returnValue(true);
49+
50+
const voidElement = TagElementType(voidNode, 'key');
51+
expect(voidElement.type).toBe('void');
52+
expect(voidElement.props.children).toBe(null);
53+
54+
});
55+
3656
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import isVoidElement from 'utils/isVoidElement';
2+
3+
describe('Testing `utils/isVoidElement`', () => {
4+
5+
it('should return whether the element is a void element', () => {
6+
expect(isVoidElement('img')).toBe(true);
7+
expect(isVoidElement('br')).toBe(true);
8+
expect(isVoidElement('div')).toBe(false);
9+
expect(isVoidElement('p')).toBe(false);
10+
});
11+
12+
});

0 commit comments

Comments
 (0)