How to use the inferno-compat.createClass function in inferno-compat

To help you get started, we’ve selected a few inferno-compat 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-compat / __tests__ / ReactComponentLifeCycle.spec.jsx View on Github external
it('should not allow update state inside of getInitialState', function() {
    spyOn(console, 'error');
    var StatefulComponent = React.createClass({
      getInitialState: function() {
        this.setState({ stateField: 'something' });

        return { stateField: 'somethingelse' };
      },
      render: function() {
        return <div>;
      }
    });
    expect(() =&gt; renderIntoDocument()).toThrow();
    // expect(console.error.calls.count()).toBe(1);
    // expect(console.error.argsForCall[0][0]).toBe(
    //   'Warning: setState(...): Can only update a mounted or ' +
    //   'mounting component. This usually means you called setState() on an ' +
    //   'unmounted component. This is a no-op. Please check the code for the ' +
    //   'StatefulComponent component.'</div>
github infernojs / inferno / packages / inferno-compat / __tests__ / ReactCompositeComponentState.spec.jsx View on Github external
it('should batch unmounts', function() {
    var outer;
    var Inner = React.createClass({
      render: function() {
        return <div>;
      },
      componentWillUnmount: function() {
        // This should get silently ignored (maybe with a warning), but it
        // shouldn't break React.
        outer.setState({ showInner: false });
      }
    });
    var Outer = React.createClass({
      getInitialState: function() {
        return { showInner: true };
      },
      render: function() {
        return <div>{this.state.showInner &amp;&amp; }</div>;
      }</div>
github infernojs / inferno / packages / inferno-compat / __tests__ / ReactComponentLifeCycle.spec.jsx View on Github external
it('should call nested lifecycle methods in the right order', function() {
    var log;
    var logger = function(msg) {
      return function() {
        // return true for shouldComponentUpdate
        log.push(msg);
        return true;
      };
    };
    var Outer = React.createClass({
      render: function() {
        return (
          <div>
            
          </div>
        );
      },
      componentWillMount: logger('outer componentWillMount'),
      componentDidMount: logger('outer componentDidMount'),
      componentWillReceiveProps: logger('outer componentWillReceiveProps'),
      shouldComponentUpdate: logger('outer shouldComponentUpdate'),
      componentWillUpdate: logger('outer componentWillUpdate'),
      componentDidUpdate: logger('outer componentDidUpdate'),
      componentWillUnmount: logger('outer componentWillUnmount')
    });
    var Inner = React.createClass({
github infernojs / inferno / packages / inferno-compat / __tests__ / ReactComponent.spec.jsx View on Github external
it('should support refs on owned components', function() {
    var innerObj = {};
    var outerObj = {};

    var Wrapper = React.createClass({
      getObject: function() {
        return this.props.object;
      },

      render: function() {
        return <div>{this.props.children}</div>;
      }
    });

    var Component = React.createClass({
      render: function() {
        var inner = ;
        var outer = (
          
            {inner}
          
        );
        return outer;
      },
      componentDidMount: function() {
        expect(this.refs.inner.getObject()).toEqual(innerObj);
        expect(this.refs.outer.getObject()).toEqual(outerObj);
      }
    });

    var instance = ;
github infernojs / inferno / packages / inferno-compat / __tests__ / ReactClass.spec.jsx View on Github external
it('renders based on context getInitialState', function() {
    var Foo = React.createClass({
      contextTypes: {
        className: React.PropTypes.string
      },
      getInitialState() {
        return { className: this.context.className };
      },
      render() {
        return <span>;
      }
    });

    var Outer = React.createClass({
      childContextTypes: {
        className: React.PropTypes.string
      },
      getChildContext() {</span>
github infernojs / inferno / packages / inferno-compat / __tests__ / ReactClass.spec.jsx View on Github external
it('should work with a null getInitialState() return value', function() {
    var Component = React.createClass({
      getInitialState: function() {
        return null;
      },
      render: function() {
        return <span>;
      }
    });
    expect(() =&gt; renderIntoDocument()).not.toThrow();
  });
</span>
github infernojs / inferno / packages / inferno-compat / __tests__ / misc.spec.jsx View on Github external
it('should not bind blacklisted methods', () => {
      let constructor = () => {};
      let render = () => null;
      const C = createClass({
        constructor,
        render
      });
      let c = new C();
      expect(c.constructor).toBe(constructor);
      expect(c.render).toBe(render);
    });
github infernojs / inferno / packages / inferno-compat / __tests__ / misc.spec.jsx View on Github external
it('should copy statics', () => {
      let def = {
        statics: {
          foo: 'bar',
          baz() {}
        }
      };
      let c = createClass(def);
      expect(c.foo).toEqual(def.statics.foo);
      expect(c.baz).toEqual(def.statics.baz);
    });
  });
github infernojs / inferno / packages / inferno-compat / __tests__ / onlyChild.spec.jsx View on Github external
beforeEach(function() {
    onlyChild = React.Children.only;
    WrapComponent = React.createClass({
      render: function() {
        return <div>{onlyChild(this.props.children, this.props.mapFn, this)}</div>;
      }
    });
  });
github infernojs / inferno / packages / inferno-compat / __tests__ / ReactCompositeComponentState.spec.jsx View on Github external
beforeEach(function() {
    TestComponent = React.createClass({
      peekAtState: function(from, state) {
        state = state || this.state;
        this.props.stateListener(from, state && state.color);
      },

      peekAtCallback: function(from) {
        return () => this.peekAtState(from);
      },

      setFavoriteColor: function(nextColor) {
        this.setState({ color: nextColor }, this.peekAtCallback('setFavoriteColor'));
      },

      getInitialState: function() {
        this.peekAtState('getInitialState');
        return { color: 'red' };