How to use the inferno.createTextVNode function in inferno

To help you get started, we’ve selected a few inferno examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github infernojs / inferno / packages / inferno-server / __tests__ / hydration-ext.spec.server.jsx View on Github external
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!');
  });
github infernojs / inferno / packages / inferno / __tests__ / patching.spec.jsx View on Github external
const spyObj2 = { fn: () =&gt; {} };
    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);
github infernojs / inferno / packages / inferno / __tests__ / rendering.spec.jsx View on Github external
it('null/undefined textNodes should render empty text', () =&gt; {
      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>');
    });
github infernojs / inferno / packages / inferno-create-element / __tests__ / validations.spec.jsx View on Github external
it('Should throw error if two duplicate TEXTs is found with same key', () =&gt; {
        const errorNode = (
          <div>
            {createTextVNode('foo', 'foo')}
            {createTextVNode('foo2', 'foo')}
          </div>
        );

        expect(() =&gt; render(errorNode, container)).toThrowError(
          'Inferno Error: Encountered two children with same key: {foo}. Location: \n&gt;&gt; Text(foo2)\n&gt;&gt; <div>'
        );
      });
</div>
github infernojs / inferno / packages / inferno / __tests__ / rendering.spec.jsx View on Github external
it('Should create new object when dom exists', () =&gt; {
    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>');
  });
github infernojs / inferno / packages / inferno / __tests__ / rendering.spec.jsx View on Github external
it('null/undefined textNodes should render empty text', () =&gt; {
      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>');
    });
github infernojs / inferno / packages / inferno-create-element / __tests__ / validations.spec.jsx View on Github external
it('Should support long chain of rendered nodes', () =&gt; {
        const errorNode = (
          <div>
            <div id="another">
              <div data-attr="foobar">
                <div>
                  {createTextVNode('foo', 'foo')}
                  {null}
                </div>
              </div>
            </div>
          </div>
        );

        expect(() =&gt; {
          return render(errorNode, container);
        }).toThrowError('Inferno Error: Encountered invalid node with mixed keys. Location: \n');
      });
    });
github infernojs / inferno / packages / inferno / __tests__ / patching.spec.jsx View on Github external
it('Should mount nextNode if lastNode crashed', () =&gt; {
    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>');
  });
github infernojs / inferno-website / src / components / Home.js View on Github external
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>
github infernojs / inferno / packages / inferno-clone-vnode / src / index.ts View on Github external
} 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)
  );
}