How to use the inferno-test-utils.findRenderedVNodeWithType function in inferno-test-utils

To help you get started, we’ve selected a few inferno-test-utils 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-redux / __tests__ / components / connect.spec.js View on Github external
};
        }

        render() {
          return ;
        }
      }

      const tree = renderToContainer(
        
          
        
      );

      const target = findRenderedVNodeWithType(tree, Passthrough).children;
      const wrapper = findRenderedVNodeWithType(tree, StatefulWrapper).children;

      expect(mapStateToPropsCalls).toBe(2);
      expect(mapDispatchToPropsCalls).toBe(2);
      expect(target.props.statefulValue).toBe('foo');

      // Impure update
      const storeGetter = wrapper.state.storeGetter;
      storeGetter.storeKey = 'bar';
      wrapper.setState({ storeGetter });

      expect(mapStateToPropsCalls).toBe(3);
      expect(mapDispatchToPropsCalls).toBe(3);
      expect(target.props.statefulValue).toBe('bar');
    });
github infernojs / inferno / packages / inferno-redux / __tests__ / components / connect.spec.js View on Github external
() => ({ scooby: 'boo' })
      )(
        class ContainerNext extends Component {
          render() {
            return ;
          }
        }
      );

      const tree = renderToContainer(
        
          
        
      );

      const container = findRenderedVNodeWithType(tree, ContainerBefore).children;
      const stub = findRenderedVNodeWithType(tree, Passthrough).children;
      expect(stub.props.foo).toBeUndefined();
      expect(stub.props.scooby).toBe('doo');

      const imitateHotReloading = (TargetClass, SourceClass) => {
        // Crude imitation of hot reloading that does the job
        Object.getOwnPropertyNames(SourceClass.prototype)
          .filter(key => typeof SourceClass.prototype[key] === 'function')
          .forEach(key => {
            if (key !== 'render' && key !== 'constructor') {
              TargetClass.prototype[key] = SourceClass.prototype[key];
            }
          });

        container.forceUpdate();
      };
github infernojs / inferno / packages / inferno-redux / __tests__ / components / Provider.spec.js View on Github external
it('should add the store to the child context', () => {
      const store1 = createStore(() => ({}));
      const store2 = createStore(() => ({}));

      const spy = spyOn(console, 'error');

      let tree = renderIntoContainer(createElement(Provider, { store: store1 }, createElement(Child, {})));
      expect(spy.calls.count()).toEqual(0);

      let child = findRenderedVNodeWithType(tree, Child).children;
      expect(child.context.store).toBe(store1);

      tree = renderIntoContainer(createElement(Provider, { store: store1 }, createElement(Provider, { store: store2 }, createElement(Child, {}))));

      expect(spy.calls.count()).toEqual(0);

      child = findRenderedVNodeWithType(tree, Child).children;
      expect(child.context.store).toBe(store2);
    });
github infernojs / inferno / packages / inferno-test-utils / __tests__ / testutilevents.spec.jsx View on Github external
it('Should work with Synthetic events', () => {
    const testObj = {
      clicker: () => {}
    };

    const sinonSpy = sinon.spy(testObj, 'clicker');

    class FooBar extends Component {
      render() {
        return <div>Test</div>;
      }
    }
    const tree = renderIntoDocument();

    const vnode = findRenderedVNodeWithType(tree, 'div');
    vnode.dom.click();

    expect(sinonSpy.callCount).toEqual(1);
  });
github infernojs / inferno / packages / inferno-redux / __tests__ / components / connect.spec.js View on Github external
);

        const vNode = (
          
            
          
        );
        const tree = renderToContainer(vNode);

        const stub = findRenderedVNodeWithType(tree, Passthrough).children;
        expect(stub.props.dispatch).toBe(store.dispatch);
        expect(stub.props.foo).toBeUndefined();
        expect(stub.props.pass).toBe('through');
        expect(() =&gt; findRenderedVNodeWithType(tree, Container).children).not.toThrowError();

        const decorated = findRenderedVNodeWithType(tree, Container).children;
        expect(decorated.isSubscribed()).toBe(false);
      };
github infernojs / inferno / packages / inferno-redux / __tests__ / components / connect.spec.js View on Github external
return ;
        }
      }

      renderToContainer(
        
           {
              container = instance;
            }}
          /&gt;
        
      );

      const propsBefore = {
        ...findRenderedVNodeWithType(container, Passthrough).children.props
      };

      props = {};
      container.forceUpdate();

      const propsAfter = {
        ...findRenderedVNodeWithType(container, Passthrough).children.props
      };

      expect(propsBefore.x).toBe(true);
      expect('x' in propsAfter).toBe(false);
    });
github infernojs / inferno / packages / inferno-redux / __tests__ / components / connect.spec.js View on Github external
this.setState({
            bar
          });
        }

        render() {
          return (
            
              
            
          );
        }
      }

      const tree = renderToContainer();
      const stub = findRenderedVNodeWithType(tree, Passthrough).children;
      expect(stub.props.foo).toBe('bar');
      expect(stub.props.pass).toBe('');
    });
github infernojs / inferno / packages / inferno-redux / __tests__ / components / connect.spec.js View on Github external
class Container extends Component {
        render() {
          return ;
        }
      }

      const decorator = connect(state =&gt; state);
      const Decorated = decorator(Container);

      const tree = renderToContainer(
        
          
        
      );

      const decorated = findRenderedVNodeWithType(tree, Decorated).children;
      expect(() =&gt; decorated.getWrappedInstance()).toThrowError(
        /To access the wrapped instance, you need to specify \{ withRef: true \} in the options argument of the connect\(\) call\./
      );
    });
github infernojs / inferno / packages / inferno-redux / __tests__ / components / connect.spec.js View on Github external
constructor() {
          super();
          this.state = { extra: 'z' };
        }

        render() {
          return (
            
              
            
          );
        }
      }

      const outerStub = render(, document.createElement('div'));
      const stub = findRenderedVNodeWithType(outerStub, Passthrough).children;
      expect(stub.props.stateThing).toBe('');
      stub.props.mergedDoSomething('a');
      outerStub.setState({}, () =&gt; {
        expect(stub.props.stateThing).toBe('HELLO az');

        stub.props.mergedDoSomething('b');
        outerStub.setState({}, () =&gt; {
          expect(stub.props.stateThing).toBe('HELLO azbz');

          outerStub.setState({ extra: 'Z' });
          outerStub.setState({}, () =&gt; {
            stub.props.mergedDoSomething('c');
            outerStub.setState({}, () =&gt; {
              expect(stub.props.stateThing).toBe('HELLO azbzcZ');

              done();
github infernojs / inferno / packages / inferno-redux / __tests__ / components / connect.spec.js View on Github external
super(props);
          this.state = { pass: '' };
        }

        render() {
          return (
            
              
            
          );
        }
      }

      const vNode = ;
      const rootStub = renderToContainer(vNode);
      const stub = findRenderedVNodeWithType(rootStub, Passthrough).children;

      expect(renderCallCount).toBe(1);
      expect(stub.props.string).toBe('');
      expect(stub.props.pass).toBe('');

      store.dispatch({ type: 'APPEND', payload: 'a' });
      renderToContainer(vNode);
      expect(renderCallCount).toBe(2);
      expect(stub.props.string).toBe('a');
      expect(stub.props.pass).toBe('');

      rootStub.setState({ pass: '' });
      renderToContainer(vNode);
      expect(renderCallCount).toBe(2);
      expect(stub.props.string).toBe('a');
      expect(stub.props.pass).toBe('');