acdlite/recompose

Copy this badge! ↑
  • test('branch tests props and applies one of two HoCs, for true and false', () => {
      const SayMyName = compose(withState('isBad', 'updateIsBad', false), branch(props => props.isBad, withProps({
        name: 'Heisenberg'
      }), withProps({
        name: 'Walter'
      })))(({
        isBad,
        name,
        updateIsBad
      }) => /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
        className: "isBad"
      }, isBad ? 'true' : 'false'), /*#__PURE__*/React.createElement("div", {
        className: "name"
      }, name), /*#__PURE__*/React.createElement("button", {
        onClick: () => updateIsBad(b => !b)
      }, "Toggle")));
      expect(SayMyName.displayName).toBe('withState(branch(Component))');
      const wrapper = mount( /*#__PURE__*/React.createElement(SayMyName, null));
    
      const getIsBad = () => wrapper.find('.isBad').text();
    
      const getName = () => wrapper.find('.name').text();
    
      const toggle = wrapper.find('button');
      expect(getIsBad()).toBe('false');
      expect(getName()).toBe('Walter');
      toggle.simulate('click');
      expect(getIsBad()).toBe('true');
      expect(getName()).toBe('Heisenberg');
    });
  • test('branch defaults third argument to identity function', () => {
      const Left = () => /*#__PURE__*/React.createElement("div", {
        className: "left"
      }, "Left");
    
      const Right = () => /*#__PURE__*/React.createElement("div", {
        className: "right"
      }, "Right");
    
      const BranchedComponent = branch(() => false, () => props => /*#__PURE__*/React.createElement(Left, props))(Right);
      const wrapper = mount( /*#__PURE__*/React.createElement(BranchedComponent, null));
      const right = wrapper.find('.right').text();
      expect(right).toBe('Right');
    });
  • test('branch third argument should not cause console error', () => {
      const error = sinon.stub(console, 'error');
    
      const Component = () => /*#__PURE__*/React.createElement("div", {
        className: "right"
      }, "Component");
    
      const BranchedComponent = branch(() => false, v => v, v => v)(Component);
      mount( /*#__PURE__*/React.createElement(BranchedComponent, null));
      expect(error.called).toBe(false);
      /* eslint-disable */
    
      error.restore();
      /* eslint-enable */
    });
  • test('componentFromProp creates a component that takes a component as a prop and renders it with the rest of the props', () => {
      const Container = componentFromProp('component');
      expect(Container.displayName).toBe('componentFromProp(component)');
    
      const Component = ({
        pass
      }) => /*#__PURE__*/React.createElement("div", null, "Pass: ", pass);
    
      const wrapper = mount( /*#__PURE__*/React.createElement(Container, {
        component: Component,
        pass: "through"
      }));
      const div = wrapper.find('div');
      expect(div.text()).toBe('Pass: through');
    });
  • test('componentFromStream creates a component from a prop stream transformation', () => {
      const Double = componentFromStream(props$ => props$.map(({
        n
      }) => /*#__PURE__*/React.createElement("div", null, n * 2)));
      const wrapper = mount( /*#__PURE__*/React.createElement(Double, {
        n: 112
      }));
      const div = wrapper.find('div');
      expect(div.text()).toBe('224');
      wrapper.setProps({
        n: 358
      });
      expect(div.text()).toBe('716');
    });
  • test('componentFromStream unsubscribes from stream before unmounting', () => {
      let subscriptions = 0;
      const vdom$ = new Observable(observer => {
        subscriptions += 1;
        observer.next( /*#__PURE__*/React.createElement("div", null));
        return {
          unsubscribe() {
            subscriptions -= 1;
          }
    
        };
      });
      const Div = componentFromStream(() => vdom$);
      const wrapper = mount( /*#__PURE__*/React.createElement(Div, null));
      expect(subscriptions).toBe(1);
      wrapper.unmount();
      expect(subscriptions).toBe(0);
    });
  • test('componentFromStream renders nothing until the stream emits a value', () => {
      const vdom$ = new Subject();
      const Div = componentFromStream(() => vdom$.mapTo( /*#__PURE__*/React.createElement("div", null)));
      const wrapper = mount( /*#__PURE__*/React.createElement(Div, null));
      expect(wrapper.find('div').length).toBe(0);
      vdom$.next();
      wrapper.update();
      expect(wrapper.find('div').length).toBe(1);
    });
  • test('handler multiple observers of props stream', () => {
      const Other = () => /*#__PURE__*/React.createElement("div", null);
    
      const Div = componentFromStream(props$ => // Adds three observers to props stream
      props$.combineLatest(props$, props$, props1 => /*#__PURE__*/React.createElement(Other, props1)));
      const wrapper = mount( /*#__PURE__*/React.createElement(Div, {
        "data-value": 1
      }));
      const div = wrapper.find(Other);
      expect(div.prop('data-value')).toBe(1);
      wrapper.setProps({
        'data-value': 2
      });
      wrapper.update();
      const div2 = wrapper.find(Other);
      expect(div2.prop('data-value')).toBe(2);
    });
  • test('complete props stream before unmounting', () => {
      let counter = 0;
      const Div = componentFromStream(props$ => {
        const first$ = props$.first().do(() => {
          counter += 1;
        });
        const last$ = props$.last().do(() => {
          counter -= 1;
        }).startWith(null);
        return props$.combineLatest(first$, last$, props1 => /*#__PURE__*/React.createElement("div", props1));
      });
      const wrapper = mount( /*#__PURE__*/React.createElement(Div, null));
      expect(counter).toBe(1);
      expect(wrapper.find('div').length).toBe(1);
      wrapper.unmount();
      expect(counter).toBe(0);
    });
  • test('completed props stream should throw an exception', () => {
      const Div = componentFromStream(props$ => {
        const first$ = props$.filter(() => false).first().startWith(null);
        return props$.combineLatest(first$, props1 => /*#__PURE__*/React.createElement("div", props1));
      });
      const wrapper = mount( /*#__PURE__*/React.createElement(Div, null));
      expect(wrapper.find('div').length).toBe(1);
      const error = sinon.stub(console, 'error');
      expect(() => wrapper.unmount()).toThrowError(/no elements in sequence/);
      expect(error.called).toBe(true);
    });
  • test('componentFromStreamWithConfig creates a stream with the correct stream type.', () => {
      const MostComponent = componentFromStreamWithConfig(mostConfig)(props$ => {
        expect(props$ instanceof MostStream).toBe(true);
        return props$.map(v => /*#__PURE__*/React.createElement("div", null, String(v)));
      });
      mount( /*#__PURE__*/React.createElement(MostComponent, null));
      const RXJSComponent = componentFromStreamWithConfig(rxjsConfig)(props$ => {
        expect(props$ instanceof Observable).toBe(true);
        return props$.map(v => /*#__PURE__*/React.createElement("div", null, String(v)));
      });
      mount( /*#__PURE__*/React.createElement(RXJSComponent, null));
    });
  • test('compose composes from right to left', () => {
      const double = x => x * 2;
    
      const square = x => x * x;
    
      expect(compose(square)(5)).toBe(25);
      expect(compose(square, double)(5)).toBe(100);
      expect(compose(double, square, double)(5)).toBe(200);
    });
  • test('compose can be seeded with multiple arguments', () => {
      const square = x => x * x;
    
      const add = (x, y) => x + y;
    
      expect(compose(square, add)(1, 2)).toBe(9);
    });
  • test('compose returns the identity function if given no arguments', () => {
      expect(compose()(1, 2)).toBe(1);
      expect(compose()(3)).toBe(3);
      expect(compose()()).toBe(undefined);
    });
  • test('compose returns the first function if given only one', () => {
      const fn = x => x * x;
    
      expect(compose(fn)(3)).toBe(fn(3));
    });
  • test('createEventHandler creates an event handler and a corresponding stream', () => {
      const result = [];
      const {
        stream,
        handler
      } = createEventHandler();
      const subscription = stream.subscribe({
        next: v => result.push(v)
      });
      handler(1);
      handler(2);
      handler(3);
      subscription.unsubscribe();
      expect(result).toEqual([1, 2, 3]);
    });
  • test('handles multiple subscribers', () => {
      const result1 = [];
      const result2 = [];
      const {
        handler,
        stream
      } = createEventHandler();
      const subscription1 = stream.subscribe({
        next: v => result1.push(v)
      });
      const subscription2 = stream.subscribe({
        next: v => result2.push(v)
      });
      handler(1);
      handler(2);
      handler(3);
      subscription1.unsubscribe();
      subscription2.unsubscribe();
      expect(result1).toEqual([1, 2, 3]);
      expect(result2).toEqual([1, 2, 3]);
    });
  • test('createSink creates a React component that fires a callback when receiving new props', () => {
      const spy = sinon.spy();
      const Sink = createSink(spy);
      const Counter = compose(withState('counter', 'updateCounter', 0), mapProps(({
        updateCounter,
        ...rest
      }) => ({
        increment: () => updateCounter(n => n + 1),
        ...rest
      })))(Sink);
      mount( /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Counter, null)));
      const {
        increment
      } = spy.lastCall.args[0];
    
      const getCounter = () => spy.lastCall.args[0].counter;
    
      expect(getCounter()).toBe(0);
      increment();
      expect(getCounter()).toBe(1);
      increment();
      expect(getCounter()).toBe(2);
    });
  • test('defaultProps passes additional props to base component', () => {
      const DoReMi = defaultProps({
        'data-so': 'do',
        'data-la': 'fa'
      })('div');
      expect(DoReMi.displayName).toBe('defaultProps(div)');
      const div = shallow( /*#__PURE__*/React.createElement(DoReMi, null)).find('div');
      expect(div.equals( /*#__PURE__*/React.createElement("div", {
        "data-so": "do",
        "data-la": "fa"
      }))).toBe(true);
    });
  • test('defaultProps has lower precendence than props from owner', () => {
      const DoReMi = defaultProps({
        'data-so': 'do',
        'data-la': 'fa'
      })('div');
      expect(DoReMi.displayName).toBe('defaultProps(div)');
      const div = shallow( /*#__PURE__*/React.createElement(DoReMi, {
        "data-la": "ti"
      })).find('div');
      expect(div.equals( /*#__PURE__*/React.createElement("div", {
        "data-so": "do",
        "data-la": "ti"
      }))).toBe(true);
    });
  • test('defaultProps overrides undefined owner props', () => {
      const DoReMi = defaultProps({
        'data-so': 'do',
        'data-la': 'fa'
      })('div');
      expect(DoReMi.displayName).toBe('defaultProps(div)');
      const div = shallow( /*#__PURE__*/React.createElement(DoReMi, {
        "data-la": undefined
      })).find('div');
      expect(div.equals( /*#__PURE__*/React.createElement("div", {
        "data-so": "do",
        "data-la": "fa"
      }))).toBe(true);
    });
  • test('flattenProps flattens an object prop and spreads it into the top-level props object', () => {
      const Counter = flattenProp('data-state')('div');
      expect(Counter.displayName).toBe('flattenProp(div)');
      const wrapper = shallow( /*#__PURE__*/React.createElement(Counter, {
        "data-pass": "through",
        "data-state": {
          'data-counter': 1
        }
      }));
      expect(wrapper.equals( /*#__PURE__*/React.createElement("div", {
        "data-pass": "through",
        "data-state": {
          'data-counter': 1
        },
        "data-counter": 1
      }))).toBe(true);
      wrapper.setProps({
        'data-pass': 'through',
        'data-state': {
          'data-state': 1
        }
      });
      expect(wrapper.equals( /*#__PURE__*/React.createElement("div", {
        "data-pass": "through",
        "data-state": 1
      }))).toBe(true);
    });
  • test('fromRenderProps passes additional props to base component', () => {
      const RenderPropsComponent = ({
        children
      }) => children({
        i18n: 'zh-TW'
      });
    
      const EnhancedComponent = fromRenderProps(RenderPropsComponent, ({
        i18n
      }) => ({
        i18n
      }))('div');
      expect(EnhancedComponent.displayName).toBe('fromRenderProps(div)');
      const div = mount( /*#__PURE__*/React.createElement(EnhancedComponent, null));
      expect(div.html()).toBe(`<div i18n="zh-TW"></div>`);
    });
  • test('fromRenderProps passes additional props to base component with custom renderPropName', () => {
      const RenderPropsComponent = ({
        render
      }) => render({
        i18n: 'zh-TW'
      });
    
      const EnhancedComponent = fromRenderProps(RenderPropsComponent, ({
        i18n
      }) => ({
        i18n
      }), 'render')('div');
      expect(EnhancedComponent.displayName).toBe('fromRenderProps(div)');
      const div = mount( /*#__PURE__*/React.createElement(EnhancedComponent, null));
      expect(div.html()).toBe(`<div i18n="zh-TW"></div>`);
    });
  • test('fromRenderProps passes additional props to base component with 2 RenderPropsComponents', () => {
      const RenderPropsComponent1 = ({
        children
      }) => children({
        theme: 'dark'
      });
    
      const RenderPropsComponent2 = ({
        render
      }) => render({
        i18n: 'zh-TW'
      });
    
      const EnhancedComponent = compose(fromRenderProps(RenderPropsComponent1, ({
        theme
      }) => ({
        theme
      }), 'children'), fromRenderProps(RenderPropsComponent2, ({
        i18n
      }) => ({
        locale: i18n
      }), 'render'))('div');
      expect(EnhancedComponent.displayName).toBe('fromRenderProps(fromRenderProps(div))');
      const div = mount( /*#__PURE__*/React.createElement(EnhancedComponent, null));
      expect(div.html()).toBe(`<div theme="dark" locale="zh-TW"></div>`);
    });
  • test('fromRenderProps meet toRenderProps', () => {
      const RenderPropsComponent = toRenderProps(defaultProps({
        foo1: 'bar1',
        foo2: 'bar2'
      }));
      const EnhancedComponent = fromRenderProps(RenderPropsComponent, ({
        foo1
      }) => ({
        foo: foo1
      }))('div');
      expect(EnhancedComponent.displayName).toBe('fromRenderProps(div)');
      const div = mount( /*#__PURE__*/React.createElement(EnhancedComponent, null));
      expect(div.html()).toBe(`<div foo="bar1"></div>`);
    });
  • test('fromRenderProps with multiple arguments #693', () => {
      const RenderPropsComponent = ({
        children
      }) => children({
        theme: 'dark'
      }, {
        data: 'data'
      });
    
      const EnhancedComponent = compose(fromRenderProps(RenderPropsComponent, ({
        theme
      }, {
        data
      }) => ({
        theme,
        data
      }), 'children'))('div');
      expect(EnhancedComponent.displayName).toBe('fromRenderProps(div)');
      const div = mount( /*#__PURE__*/React.createElement(EnhancedComponent, null));
      expect(div.html()).toBe(`<div theme="dark" data="data"></div>`);
    });
  • test('getContext works', () => expect(true).toBe(true));
  • test('getDisplayName gets the display name of a React component', () => {
      class SomeComponent extends React.Component {
        render() {
          return /*#__PURE__*/React.createElement("div", null);
        }
    
      }
    
      class SomeOtherComponent extends React.Component {
        static displayName = 'CustomDisplayName';
    
        render() {
          return /*#__PURE__*/React.createElement("div", null);
        }
    
      }
    
      function YetAnotherComponent() {
        return /*#__PURE__*/React.createElement("div", null);
      }
    
      expect(getDisplayName(SomeComponent)).toBe('SomeComponent');
      expect(getDisplayName(SomeOtherComponent)).toBe('CustomDisplayName');
      expect(getDisplayName(YetAnotherComponent)).toBe('YetAnotherComponent');
      expect(getDisplayName(() => /*#__PURE__*/React.createElement("div", null))).toBe('Component');
      expect(getDisplayName('div')).toBe('div');
    });
  • test('copies non-React static properties from base component to new component', () => {
      const BaseComponent = sinon.spy(() => null);
    
      BaseComponent.foo = () => {};
    
      const EnhancedComponent = hoistStatics(mapProps(props => ({
        n: props.n * 5
      })))(BaseComponent);
      expect(EnhancedComponent.foo).toBe(BaseComponent.foo);
      mount( /*#__PURE__*/React.createElement(EnhancedComponent, {
        n: 3
      }));
      expect(BaseComponent.firstCall.args[0].n).toBe(15);
    });
  • test('does not copy blacklisted static properties to new component ', () => {
      const BaseComponent = sinon.spy(() => null);
    
      BaseComponent.foo = () => {};
    
      BaseComponent.bar = () => {};
    
      const EnhancedComponent = hoistStatics(comp => /*#__PURE__*/createFactory(comp), {
        bar: true
      } // Blacklist
      )(BaseComponent);
      expect(EnhancedComponent.foo).toBe(BaseComponent.foo);
      expect(EnhancedComponent.bar).toBe(undefined);
    });
  • test('isClassComponent returns false for functions', () => {
      const Foo = () => /*#__PURE__*/React.createElement("div", null);
    
      expect(isClassComponent(Foo)).toBe(false);
    });
  • test('isClassComponent returns true for React component classes', () => {
      class Foo extends Component {
        render() {
          return /*#__PURE__*/React.createElement("div", null);
        }
    
      }
      /* eslint-disable react/prefer-es6-class */
    
    
      const Bar = createReactClass({
        displayName: "Bar",
    
        render() {
          return /*#__PURE__*/React.createElement("div", null);
        }
    
      });
      /* eslint-enable react/prefer-es6-class */
    
      expect(isClassComponent(Foo)).toBe(true);
      expect(isClassComponent(Bar)).toBe(true);
    });
  • test('lifecycle is a higher-order component version of React.Component', () => {
      const enhance = lifecycle({
        componentWillMount() {
          this.setState({
            'data-bar': 'baz'
          });
        }
    
      });
      const Div = enhance('div');
      expect(Div.displayName).toBe('lifecycle(div)');
      const div = mount( /*#__PURE__*/React.createElement(Div, {
        "data-foo": "bar"
      })).find('div');
      expect(div.prop('data-foo')).toBe('bar');
      expect(div.prop('data-bar')).toBe('baz');
    });
  • test('mapProps maps owner props to child props', () => {
      const component = sinon.spy(() => null);
      component.displayName = 'component';
      const StringConcat = compose(withState('strings', 'updateStrings', ['do', 're', 'mi']), mapProps(({
        strings,
        ...rest
      }) => ({ ...rest,
        string: strings.join('')
      })))(component);
      expect(StringConcat.displayName).toBe('withState(mapProps(component))');
      mount( /*#__PURE__*/React.createElement(StringConcat, null));
      const {
        updateStrings
      } = component.firstCall.args[0];
      updateStrings(strings => [...strings, 'fa']);
      expect(component.firstCall.args[0].string).toBe('doremi');
      expect(component.secondCall.args[0].string).toBe('doremifa');
    });
  • test('mapPropsStream creates a higher-order component from a stream', () => {
      const Double = mapPropsStream(props$ => props$.map(({
        n
      }) => ({
        children: n * 2
      })))('div');
      const wrapper = mount( /*#__PURE__*/React.createElement(Double, {
        n: 112
      }));
      const div = wrapper.find('div');
      expect(div.text()).toBe('224');
      wrapper.setProps({
        n: 358
      });
      expect(div.text()).toBe('716');
    });
  • test('mapPropsStreamWithConfig creates a higher-order component from a stream and a observable config', () => {
      const Double = mapPropsStreamWithConfig(rxConfig)(props$ => props$.map(({
        n
      }) => ({
        children: n * 2
      })))('div');
      const wrapper = mount( /*#__PURE__*/React.createElement(Double, {
        n: 112
      }));
      const div = wrapper.find('div');
      expect(div.text()).toBe('224');
      wrapper.setProps({
        n: 358
      });
      expect(div.text()).toBe('716');
    });
  • test('mapPropsStreamWithConfig creates a stream with the correct config', () => {
      const MostComponent = mapPropsStreamWithConfig(mostConfig)(props$ => {
        expect(props$ instanceof MostStream).toBe(true);
        return props$.map(v => v);
      })('div');
      mount( /*#__PURE__*/React.createElement(MostComponent, null));
      const RXJSComponent = mapPropsStreamWithConfig(rxConfig)(props$ => {
        expect(props$ instanceof Observable).toBe(true);
        return props$.map(v => v);
      })('div');
      mount( /*#__PURE__*/React.createElement(RXJSComponent, null));
    });
  • test('nest nests components from outer to inner', () => {
      const A = setDisplayName('A')(toClass('div'));
      const B = setDisplayName('B')(toClass('div'));
      const C = setDisplayName('C')(toClass('div'));
      const Nest = nest(A, B, C);
      expect(Nest.displayName).toBe('nest(A, B, C)');
      const wrapper = shallow( /*#__PURE__*/React.createElement(Nest, {
        pass: "through"
      }, "Child"));
      expect(wrapper.equals( /*#__PURE__*/React.createElement(A, {
        pass: "through"
      }, /*#__PURE__*/React.createElement(B, {
        pass: "through"
      }, /*#__PURE__*/React.createElement(C, {
        pass: "through"
      }, "Child"))))).toBe(true);
    });
  • test('onlyUpdateForKeys implements shouldComponentUpdate()', () => {
      const component = sinon.spy(() => null);
      component.displayName = 'component';
      const Counter = compose(withState('counter', 'updateCounter', 0), withState('foobar', 'updateFoobar', 'foobar'), onlyUpdateForKeys(['counter']))(component);
      expect(Counter.displayName).toBe('withState(withState(onlyUpdateForKeys(component)))');
      mount( /*#__PURE__*/React.createElement(Counter, null));
      const {
        updateCounter,
        updateFoobar
      } = component.firstCall.args[0];
      expect(component.lastCall.args[0].counter).toBe(0);
      expect(component.lastCall.args[0].foobar).toBe('foobar'); // Does not update
    
      updateFoobar('barbaz');
      expect(component.calledOnce).toBe(true);
      updateCounter(42);
      expect(component.calledTwice).toBe(true);
      expect(component.lastCall.args[0].counter).toBe(42);
      expect(component.lastCall.args[0].foobar).toBe('barbaz');
    });
  • test('onlyUpdateForPropTypes only updates for props specified in propTypes', () => {
      const component = sinon.spy(() => null);
      component.displayName = 'component';
      const Counter = compose(withState('counter', 'updateCounter', 0), withState('foobar', 'updateFoobar', 'foobar'), onlyUpdateForPropTypes, setPropTypes({
        counter: PropTypes.number
      }))(component);
      expect(Counter.displayName).toBe('withState(withState(onlyUpdateForPropTypes(component)))');
      mount( /*#__PURE__*/React.createElement(Counter, null));
      const {
        updateCounter,
        updateFoobar
      } = component.firstCall.args[0];
      expect(component.lastCall.args[0].counter).toBe(0);
      expect(component.lastCall.args[0].foobar).toBe('foobar'); // Does not update
    
      updateFoobar('barbaz');
      expect(component.calledOnce).toBe(true);
      updateCounter(42);
      expect(component.calledTwice).toBe(true);
      expect(component.lastCall.args[0].counter).toBe(42);
      expect(component.lastCall.args[0].foobar).toBe('barbaz');
    });
  • test('onlyUpdateForPropTypes warns if BaseComponent does not have any propTypes', () => {
      const error = sinon.stub(console, 'error');
      const ShouldWarn = onlyUpdateForPropTypes('div');
      shallow( /*#__PURE__*/React.createElement(ShouldWarn, null));
      expect(error.firstCall.args[0]).toBe('A component without any `propTypes` was passed to ' + '`onlyUpdateForPropTypes()`. Check the implementation of the component ' + 'with display name "div".');
      /* eslint-disable */
    
      console.error.restore();
      /* eslint-enable */
    });
  • test('pure implements shouldComponentUpdate() using shallowEqual()', () => {
      const component = sinon.spy(() => null);
      component.displayName = 'component';
      const initialTodos = ['eat', 'drink', 'sleep'];
      const Todos = compose(withState('todos', 'updateTodos', initialTodos), pure, countRenders)(component);
      expect(Todos.displayName).toBe('withState(pure(countRenders(component)))');
      mount( /*#__PURE__*/React.createElement(Todos, null));
      const {
        updateTodos
      } = component.firstCall.args[0];
      expect(component.lastCall.args[0].todos).toBe(initialTodos);
      expect(component.lastCall.args[0].renderCount).toBe(1); // Does not re-render
    
      updateTodos(initialTodos);
      expect(component.calledOnce).toBe(true);
      updateTodos(todos => todos.slice(0, -1));
      expect(component.calledTwice).toBe(true);
      expect(component.lastCall.args[0].todos).toEqual(['eat', 'drink']);
      expect(component.lastCall.args[0].renderCount).toBe(2);
    });
  • test('renameProp renames a single prop', () => {
      const StringConcat = compose(withProps({
        'data-so': 123,
        'data-la': 456
      }), renameProp('data-so', 'data-do'))('div');
      expect(StringConcat.displayName).toBe('withProps(renameProp(div))');
      const div = mount( /*#__PURE__*/React.createElement(StringConcat, null)).find('div');
      expect(div.props()).toEqual({
        'data-do': 123,
        'data-la': 456
      });
    });
  • test('renameProps renames props', () => {
      const StringConcat = compose(withProps({
        'data-so': 123,
        'data-la': 456
      }), renameProps({
        'data-so': 'data-do',
        'data-la': 'data-fa'
      }))('div');
      expect(StringConcat.displayName).toBe('withProps(renameProps(div))');
      const div = mount( /*#__PURE__*/React.createElement(StringConcat, null)).find('div');
      expect(div.prop('data-do')).toBe(123);
      expect(div.prop('data-fa')).toBe(456);
    });
  • test('renderComponent always renders the given component', () => {
      const componentA = sinon.spy(() => null);
      const componentB = sinon.spy(() => null);
      const Foobar = compose(withState('flip', 'updateFlip', false), branch(props => props.flip, renderComponent(componentA), renderComponent(componentB)))(null);
      mount( /*#__PURE__*/React.createElement(Foobar, null));
      const {
        updateFlip
      } = componentB.firstCall.args[0];
      expect(componentB.calledOnce).toBe(true);
      expect(componentA.notCalled).toBe(true);
      updateFlip(true);
      expect(componentB.calledOnce).toBe(true);
      expect(componentA.calledOnce).toBe(true);
    });
  • test('renderNothing returns a component that renders null', () => {
      const Nothing = renderNothing('div');
      const wrapper = shallow( /*#__PURE__*/React.createElement(Nothing, null));
    
      const Parent = () => /*#__PURE__*/React.createElement(Nothing, null);
    
      const parentWrapper = shallow( /*#__PURE__*/React.createElement(Parent, null));
      expect(wrapper.type()).toBe(null);
      expect(parentWrapper.text()).toBe('<Nothing />');
    });
  • test('setDisplayName sets a static property on the base component', () => {
      const BaseComponent = () => /*#__PURE__*/React.createElement("div", null);
    
      const NewComponent = setDisplayName('Foo')(BaseComponent);
      expect(NewComponent.displayName).toBe('Foo');
    });
  • test('works with RxJS 5', () => {
      setObservableConfig(rxjs5Config);
      testTransform(props$ => props$.map(({
        n
      }) => /*#__PURE__*/React.createElement("div", null, n * 2)));
    });
  • test('works with RxJS 4', () => {
      setObservableConfig(rxjs4Config);
      testTransform(props$ => props$.map(({
        n
      }) => /*#__PURE__*/React.createElement("div", null, n * 2)));
    });
Load More