Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('Should render fragment', () => {
const fragmentA = createFragment([<div id="a1">A1</div>, <div>A2</div>], ChildFlags.HasNonKeyedChildren, 'A');
const fragmentB = createFragment([<div id="b1">B1</div>], ChildFlags.HasNonKeyedChildren, 'B');
const fragmentC = createFragment([<div id="c1">C1</div>, <div>C2</div>, <div>C3</div>], ChildFlags.HasNonKeyedChildren, 'C');
expect(
renderToSnapshot(
<div>
{fragmentA}
{fragmentB}
{fragmentC}
</div>
)
).toMatchSnapshot();
});
it('Should do nothing if lastVNode strictly equals nextVnode', () => {
const yar = createVNode(VNodeFlags.HtmlElement, 'div', null, createTextVNode('123'), ChildFlags.HasVNodeChildren, null, null, null);
const bar = createVNode(VNodeFlags.HtmlElement, 'div', null, createTextVNode('123'), ChildFlags.HasVNodeChildren, null, null, null);
let foo = createVNode(VNodeFlags.HtmlElement, 'div', null, [bar, yar], ChildFlags.HasNonKeyedChildren, null, null, null);
render(foo, container);
expect(container.innerHTML).toEqual('<div><div>123</div><div>123</div></div>');
foo = createVNode(VNodeFlags.HtmlElement, 'div', null, [bar, yar], ChildFlags.HasNonKeyedChildren, null, null, null);
render(foo, container);
expect(container.innerHTML).toEqual('<div><div>123</div><div>123</div></div>');
});
it('Should be possible to move component with fragment root', () => {
const fragmentA = createFragment([createElement('div', { id: 'a1' }, 'A1'), createElement('div', null, 'A2')], ChildFlags.HasNonKeyedChildren, 'A');
const fragmentB = createFragment([createElement('div', { id: 'b1' }, 'B1')], ChildFlags.HasNonKeyedChildren, 'B');
const fragmentC = createFragment(
[createElement('div', { id: 'c1' }, 'C1'), createElement('div', null, 'C2'), createElement('div', null, 'C3')],
ChildFlags.HasNonKeyedChildren,
'C'
);
const content = [fragmentC];
function SFC() {
return createElement(Fragment, null, createElement('span', null, '1'), createElement(Fragment, null, content), createElement('span', null, '2'));
}
render(createElement(Fragment, null, fragmentA, createElement(SFC, { key: 'sfc' }), fragmentB, fragmentC), container);
const FragmentAHtml = '<div id="a1">A1</div><div>A2</div>';
const FragmentBHtml = '<div id="b1">B1</div>';
const FragmentCHtml = '<div id="c1">C1</div><div>C2</div><div>C3</div>';
const SFCHtml = '<span>1</span>' + FragmentCHtml + '<span>2</span>';
it('Should not patch same innerHTML', () => {
container.innerHTML = '<span><span><span>child</span></span></span>';
const childelem = container.firstElementChild.firstElementChild;
const props = { dangerouslySetInnerHTML: { __html: '<span>child</span>' } };
const bar = createVNode(VNodeFlags.HtmlElement, 'span', null, null, ChildFlags.HasInvalidChildren, props, null, null);
const foo = createVNode(VNodeFlags.HtmlElement, 'span', null, [bar], ChildFlags.HasNonKeyedChildren, null, null, null);
render(foo, container);
expect(childelem).toBe(container.firstElementChild.firstElementChild);
});
it('Should render fragment', () => {
const fragmentA = createFragment([<div id="a1">A1</div>, <div>A2</div>], ChildFlags.HasNonKeyedChildren, 'A');
const fragmentB = createFragment([<div id="b1">B1</div>], ChildFlags.HasNonKeyedChildren, 'B');
const fragmentC = createFragment([<div id="c1">C1</div>, <div>C2</div>, <div>C3</div>], ChildFlags.HasNonKeyedChildren, 'C');
expect(
renderToSnapshot(
<div>
{fragmentA}
{fragmentB}
{fragmentC}
</div>
)
).toMatchSnapshot();
});
it('Should if there is one that cannot be keyed for example array', () => {
const errorNode = (
<div>
{createTextVNode('foo', 'foo')}
{null}
</div>
);
expect(() => render(errorNode, container)).toThrowError(
'Inferno Error: Encountered invalid node with mixed keys. Location: \n>> InvalidVNode(null)\n>> <div>'
);
});
</div>
render() {
return createFragment([<div>First</div>, <div>second</div>], ChildFlags.HasNonKeyedChildren);
}
}
function FunctionalComp() {
return createFragment([createElement('div', null, 'Functional')], ChildFlags.HasNonKeyedChildren);
}
render() {
return createFragment(
[<div>First</div>, createFragment([<div>Sub1</div>, <div>Sub2</div>], ChildFlags.HasNonKeyedChildren), <div>second</div>],
ChildFlags.HasNonKeyedChildren
);
}
}