Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('createTextVNode - Should handle empty textNodes correctly Github #1137 variation#3', () => {
const container = createContainerWithHTML('<span class="error"></span>');
const vNode = <span>{createTextVNode('')}</span>;
hydrate(vNode, container); // This should create empty text node
expect(container.firstChild.firstChild).not.toBeNull();
render(<span>{'Okay!'}</span>, container);
expect(container.textContent).toBe('Okay!');
});
const spyObj2 = { fn: () => {} };
const spy1 = sinon.spy(spyObj, 'fn');
const spy2 = sinon.spy(spyObj2, 'fn');
const div = createVNode(VNodeFlags.HtmlElement | VNodeFlags.ReCreate, 'div', null, createTextVNode('1'), ChildFlags.HasVNodeChildren, null, null, spy1);
render(div, container);
let firstDiv = container.firstChild;
expect(container.innerHTML).toEqual('<div>1</div>');
expect(spy1.callCount).toBe(1);
expect(spy1.getCall(0).args.length).toBe(1);
expect(spy1.getCall(0).args[0]).toEqual(firstDiv);
const div2 = createVNode(VNodeFlags.HtmlElement | VNodeFlags.ReCreate, 'div', null, createTextVNode('1'), ChildFlags.HasVNodeChildren, null, null, spy2);
render(div2, container);
expect(firstDiv).not.toBe(container.firstChild); // Div is different
// Html is the same
expect(container.innerHTML).toEqual('<div>1</div>');
// Verify all callbacks were called
expect(spy1.callCount).toBe(2);
expect(spy1.getCall(1).args.length).toBe(1);
expect(spy1.getCall(1).args[0]).toEqual(null);
expect(spy2.callCount).toBe(1);
expect(spy2.getCall(0).args.length).toBe(1);
expect(spy2.getCall(0).args[0]).toEqual(container.firstChild);
it('null/undefined textNodes should render empty text', () => {
render(<div>{createTextVNode(null)}</div>, container);
expect(container.innerHTML).toEqual('<div></div>');
render(<div>{createTextVNode(undefined)}</div>, container);
expect(container.innerHTML).toEqual('<div></div>');
render(<div>{createTextVNode('')}</div>, container);
expect(container.innerHTML).toEqual('<div></div>');
});
it('Should throw error if two duplicate TEXTs is found with same key', () => {
const errorNode = (
<div>
{createTextVNode('foo', 'foo')}
{createTextVNode('foo2', 'foo')}
</div>
);
expect(() => render(errorNode, container)).toThrowError(
'Inferno Error: Encountered two children with same key: {foo}. Location: \n>> Text(foo2)\n>> <div>'
);
});
</div>
it('Should create new object when dom exists', () => {
const bar = createVNode(VNodeFlags.HtmlElement, 'div', null, createTextVNode('123'), ChildFlags.HasVNodeChildren);
const foo = createVNode(VNodeFlags.HtmlElement, 'div', null, bar, ChildFlags.HasVNodeChildren);
render(foo, container);
expect(container.innerHTML).toEqual('<div><div>123</div></div>');
render(null, container);
render(foo, container);
expect(container.innerHTML).toEqual('<div><div>123</div></div>');
});
it('null/undefined textNodes should render empty text', () => {
render(<div>{createTextVNode(null)}</div>, container);
expect(container.innerHTML).toEqual('<div></div>');
render(<div>{createTextVNode(undefined)}</div>, container);
expect(container.innerHTML).toEqual('<div></div>');
render(<div>{createTextVNode('')}</div>, container);
expect(container.innerHTML).toEqual('<div></div>');
});
it('Should support long chain of rendered nodes', () => {
const errorNode = (
<div>
<div id="another">
<div data-attr="foobar">
<div>
{createTextVNode('foo', 'foo')}
{null}
</div>
</div>
</div>
</div>
);
expect(() => {
return render(errorNode, container);
}).toThrowError('Inferno Error: Encountered invalid node with mixed keys. Location: \n');
});
});
it('Should mount nextNode if lastNode crashed', () => {
const validNode = createVNode(VNodeFlags.HtmlElement, 'span', null, createTextVNode('a'), ChildFlags.HasVNodeChildren, null, null, null);
const invalidNode = createVNode(0, 'span');
render(validNode, container);
try {
render(invalidNode, container);
} catch (e) {
expect(e.message.indexOf('Inferno Error: mount() received an object')).not.toEqual(-1);
}
expect(container.innerHTML).toEqual('<span>a</span>');
render(validNode, container);
expect(container.innerHTML).toEqual('<span>a</span>');
});
render() {
return (
<div>
<div style="{{">
<div>
<div>
<div>
<div>
</div>
</div>
<div>
<div>
<h1>
Inferno
<small>{createTextVNode(`v${version}`)}</small>
</h1>
<h2>Inferno is an insanely fast, React-like library for building high-performance user interfaces on both the client and server.</h2>
<div>
Get Started
<a rel="noopener noreferrer" href="https://github.com/infernojs/inferno">GitHub</a>
</div>
</div>
</div>
</div>
</div>
<div style="{{">
<div style="{{"></div></div></div></div>
} else if (childLen > 1) {
children = [];
while (childLen-- > 0) {
children[childLen] = arguments[childLen + 2];
}
}
props.children = children;
if (flags & VNodeFlags.Component) {
return createComponentVNode(flags, vNodeToClone.type, !vNodeToClone.props && !props ? EMPTY_OBJ : combineFrom(vNodeToClone.props, props), key, ref);
}
if (flags & VNodeFlags.Text) {
return createTextVNode(children);
}
if (flags & VNodeFlags.Fragment) {
return createFragment(childLen === 1 ? [children] : children, ChildFlags.UnknownChildren, key);
}
return normalizeProps(
createVNode(flags, vNodeToClone.type, className, null, ChildFlags.HasInvalidChildren, combineFrom(vNodeToClone.props, props), key, ref)
);
}